mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/fileutils.rb: do not repeat command options.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6307996966
commit
16b6d69f63
2 changed files with 58 additions and 52 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Mar 5 18:40:58 2006 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* lib/fileutils.rb: do not repeat command options.
|
||||||
|
|
||||||
Sun Mar 5 18:35:03 2006 Minero Aoki <aamine@loveruby.net>
|
Sun Mar 5 18:35:03 2006 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/net/http.rb (send_request_with_body): #content_type never
|
* lib/net/http.rb (send_request_with_body): #content_type never
|
||||||
|
|
106
lib/fileutils.rb
106
lib/fileutils.rb
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
# = fileutils.rb
|
# = fileutils.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2000-2005 Minero Aoki <aamine@loveruby.net>
|
# Copyright (c) 2000-2006 Minero Aoki
|
||||||
#
|
#
|
||||||
# This program is free software.
|
# This program is free software.
|
||||||
# You can distribute/modify this program under the same terms of ruby.
|
# You can distribute/modify this program under the same terms of ruby.
|
||||||
|
@ -116,7 +116,7 @@ module FileUtils
|
||||||
# FileUtils.cd('/', :verbose => true) # chdir and report it
|
# FileUtils.cd('/', :verbose => true) # chdir and report it
|
||||||
#
|
#
|
||||||
def cd(dir, options = {}, &block) # :yield: dir
|
def cd(dir, options = {}, &block) # :yield: dir
|
||||||
fu_check_options options, :verbose
|
fu_check_options options, OPT_TABLE['cd']
|
||||||
fu_output_message "cd #{dir}" if options[:verbose]
|
fu_output_message "cd #{dir}" if options[:verbose]
|
||||||
Dir.chdir(dir, &block)
|
Dir.chdir(dir, &block)
|
||||||
fu_output_message 'cd -' if options[:verbose] and block
|
fu_output_message 'cd -' if options[:verbose] and block
|
||||||
|
@ -127,7 +127,7 @@ module FileUtils
|
||||||
module_function :chdir
|
module_function :chdir
|
||||||
|
|
||||||
OPT_TABLE['cd'] =
|
OPT_TABLE['cd'] =
|
||||||
OPT_TABLE['chdir'] = %w( verbose )
|
OPT_TABLE['chdir'] = [:verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: (none)
|
# Options: (none)
|
||||||
|
@ -163,7 +163,7 @@ module FileUtils
|
||||||
# FileUtils.mkdir 'tmp', :mode => 0700
|
# FileUtils.mkdir 'tmp', :mode => 0700
|
||||||
#
|
#
|
||||||
def mkdir(list, options = {})
|
def mkdir(list, options = {})
|
||||||
fu_check_options options, :mode, :noop, :verbose
|
fu_check_options options, OPT_TABLE['mkdir']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
|
fu_output_message "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
|
@ -174,7 +174,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :mkdir
|
module_function :mkdir
|
||||||
|
|
||||||
OPT_TABLE['mkdir'] = %w( noop verbose mode )
|
OPT_TABLE['mkdir'] = [:mode, :noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: mode noop verbose
|
# Options: mode noop verbose
|
||||||
|
@ -193,7 +193,7 @@ module FileUtils
|
||||||
# You can pass several directories at a time in a list.
|
# You can pass several directories at a time in a list.
|
||||||
#
|
#
|
||||||
def mkdir_p(list, options = {})
|
def mkdir_p(list, options = {})
|
||||||
fu_check_options options, :mode, :noop, :verbose
|
fu_check_options options, OPT_TABLE['mkdir_p']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
|
fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
|
||||||
return *list if options[:noop]
|
return *list if options[:noop]
|
||||||
|
@ -232,7 +232,7 @@ module FileUtils
|
||||||
|
|
||||||
OPT_TABLE['mkdir_p'] =
|
OPT_TABLE['mkdir_p'] =
|
||||||
OPT_TABLE['mkpath'] =
|
OPT_TABLE['mkpath'] =
|
||||||
OPT_TABLE['makedirs'] = %w( noop verbose )
|
OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
|
||||||
|
|
||||||
def fu_mkdir(path, mode) #:nodoc:
|
def fu_mkdir(path, mode) #:nodoc:
|
||||||
path = path.sub(%r</\z>, '')
|
path = path.sub(%r</\z>, '')
|
||||||
|
@ -256,7 +256,7 @@ module FileUtils
|
||||||
# FileUtils.rmdir 'somedir', :verbose => true, :noop => true
|
# FileUtils.rmdir 'somedir', :verbose => true, :noop => true
|
||||||
#
|
#
|
||||||
def rmdir(list, options = {})
|
def rmdir(list, options = {})
|
||||||
fu_check_options options, :noop, :verbose
|
fu_check_options options, OPT_TABLE['rmdir']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message "rmdir #{list.join ' '}" if options[:verbose]
|
fu_output_message "rmdir #{list.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
|
@ -266,7 +266,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :rmdir
|
module_function :rmdir
|
||||||
|
|
||||||
OPT_TABLE['rmdir'] = %w( noop verbose )
|
OPT_TABLE['rmdir'] = [:noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: force noop verbose
|
# Options: force noop verbose
|
||||||
|
@ -291,7 +291,7 @@ module FileUtils
|
||||||
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
|
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
|
||||||
#
|
#
|
||||||
def ln(src, dest, options = {})
|
def ln(src, dest, options = {})
|
||||||
fu_check_options options, :force, :noop, :verbose
|
fu_check_options options, OPT_TABLE['ln']
|
||||||
fu_output_message "ln#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "ln#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
fu_each_src_dest0(src, dest) do |s,d|
|
fu_each_src_dest0(src, dest) do |s,d|
|
||||||
|
@ -305,7 +305,7 @@ module FileUtils
|
||||||
module_function :link
|
module_function :link
|
||||||
|
|
||||||
OPT_TABLE['ln'] =
|
OPT_TABLE['ln'] =
|
||||||
OPT_TABLE['link'] = %w( noop verbose force )
|
OPT_TABLE['link'] = [:force, :noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: force noop verbose
|
# Options: force noop verbose
|
||||||
|
@ -330,7 +330,7 @@ module FileUtils
|
||||||
# FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
|
# FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
|
||||||
#
|
#
|
||||||
def ln_s(src, dest, options = {})
|
def ln_s(src, dest, options = {})
|
||||||
fu_check_options options, :force, :noop, :verbose
|
fu_check_options options, OPT_TABLE['ln_s']
|
||||||
fu_output_message "ln -s#{options[:force] ? 'f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "ln -s#{options[:force] ? 'f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
fu_each_src_dest0(src, dest) do |s,d|
|
fu_each_src_dest0(src, dest) do |s,d|
|
||||||
|
@ -344,7 +344,7 @@ module FileUtils
|
||||||
module_function :symlink
|
module_function :symlink
|
||||||
|
|
||||||
OPT_TABLE['ln_s'] =
|
OPT_TABLE['ln_s'] =
|
||||||
OPT_TABLE['symlink'] = %w( noop verbose force )
|
OPT_TABLE['symlink'] = [:force, :noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
|
@ -353,14 +353,14 @@ module FileUtils
|
||||||
# #ln_s(src, dest, :force)
|
# #ln_s(src, dest, :force)
|
||||||
#
|
#
|
||||||
def ln_sf(src, dest, options = {})
|
def ln_sf(src, dest, options = {})
|
||||||
fu_check_options options, :noop, :verbose
|
fu_check_options options, OPT_TABLE['ln_sf']
|
||||||
options = options.dup
|
options = options.dup
|
||||||
options[:force] = true
|
options[:force] = true
|
||||||
ln_s src, dest, options
|
ln_s src, dest, options
|
||||||
end
|
end
|
||||||
module_function :ln_sf
|
module_function :ln_sf
|
||||||
|
|
||||||
OPT_TABLE['ln_sf'] = %w( noop verbose )
|
OPT_TABLE['ln_sf'] = [:noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: preserve noop verbose
|
# Options: preserve noop verbose
|
||||||
|
@ -376,7 +376,7 @@ module FileUtils
|
||||||
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
|
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
|
||||||
#
|
#
|
||||||
def cp(src, dest, options = {})
|
def cp(src, dest, options = {})
|
||||||
fu_check_options options, :preserve, :noop, :verbose
|
fu_check_options options, OPT_TABLE['cp']
|
||||||
fu_output_message "cp#{options[:preserve] ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "cp#{options[:preserve] ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
fu_each_src_dest(src, dest) do |s, d|
|
fu_each_src_dest(src, dest) do |s, d|
|
||||||
|
@ -389,7 +389,7 @@ module FileUtils
|
||||||
module_function :copy
|
module_function :copy
|
||||||
|
|
||||||
OPT_TABLE['cp'] =
|
OPT_TABLE['cp'] =
|
||||||
OPT_TABLE['copy'] = %w( noop verbose preserve )
|
OPT_TABLE['copy'] = [:preserve, :noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: preserve noop verbose dereference_root remove_destination
|
# Options: preserve noop verbose dereference_root remove_destination
|
||||||
|
@ -415,7 +415,7 @@ module FileUtils
|
||||||
# # but this doesn't.
|
# # but this doesn't.
|
||||||
#
|
#
|
||||||
def cp_r(src, dest, options = {})
|
def cp_r(src, dest, options = {})
|
||||||
fu_check_options options, :preserve, :noop, :verbose, :dereference_root, :remove_destination
|
fu_check_options options, OPT_TABLE['cp_r']
|
||||||
fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
fu_each_src_dest(src, dest) do |s, d|
|
fu_each_src_dest(src, dest) do |s, d|
|
||||||
|
@ -424,7 +424,8 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :cp_r
|
module_function :cp_r
|
||||||
|
|
||||||
OPT_TABLE['cp_r'] = %w( noop verbose preserve dereference_root )
|
OPT_TABLE['cp_r'] = [:preserve, :noop, :verbose,
|
||||||
|
:dereference_root, :remove_destination]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copies a file system entry +src+ to +dest+.
|
# Copies a file system entry +src+ to +dest+.
|
||||||
|
@ -486,7 +487,7 @@ module FileUtils
|
||||||
# FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
|
# FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
|
||||||
#
|
#
|
||||||
def mv(src, dest, options = {})
|
def mv(src, dest, options = {})
|
||||||
fu_check_options options, :force, :noop, :verbose
|
fu_check_options options, OPT_TABLE['mv']
|
||||||
fu_output_message "mv#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "mv#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
fu_each_src_dest(src, dest) do |s, d|
|
fu_each_src_dest(src, dest) do |s, d|
|
||||||
|
@ -516,7 +517,7 @@ module FileUtils
|
||||||
module_function :move
|
module_function :move
|
||||||
|
|
||||||
OPT_TABLE['mv'] =
|
OPT_TABLE['mv'] =
|
||||||
OPT_TABLE['move'] = %w( noop verbose force )
|
OPT_TABLE['move'] = [:force, :noop, :verbose]
|
||||||
|
|
||||||
def rename_cannot_overwrite_file? #:nodoc:
|
def rename_cannot_overwrite_file? #:nodoc:
|
||||||
/djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
/djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
||||||
|
@ -534,7 +535,7 @@ module FileUtils
|
||||||
# FileUtils.rm 'NotExistFile', :force => true # never raises exception
|
# FileUtils.rm 'NotExistFile', :force => true # never raises exception
|
||||||
#
|
#
|
||||||
def rm(list, options = {})
|
def rm(list, options = {})
|
||||||
fu_check_options options, :force, :noop, :verbose
|
fu_check_options options, OPT_TABLE['rm']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose]
|
fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
|
@ -549,7 +550,7 @@ module FileUtils
|
||||||
module_function :remove
|
module_function :remove
|
||||||
|
|
||||||
OPT_TABLE['rm'] =
|
OPT_TABLE['rm'] =
|
||||||
OPT_TABLE['remove'] = %w( noop verbose force )
|
OPT_TABLE['remove'] = [:force, :noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
|
@ -559,7 +560,7 @@ module FileUtils
|
||||||
# #rm(list, :force => true)
|
# #rm(list, :force => true)
|
||||||
#
|
#
|
||||||
def rm_f(list, options = {})
|
def rm_f(list, options = {})
|
||||||
fu_check_options options, :noop, :verbose
|
fu_check_options options, OPT_TABLE['rm_f']
|
||||||
options = options.dup
|
options = options.dup
|
||||||
options[:force] = true
|
options[:force] = true
|
||||||
rm list, options
|
rm list, options
|
||||||
|
@ -570,7 +571,7 @@ module FileUtils
|
||||||
module_function :safe_unlink
|
module_function :safe_unlink
|
||||||
|
|
||||||
OPT_TABLE['rm_f'] =
|
OPT_TABLE['rm_f'] =
|
||||||
OPT_TABLE['safe_unlink'] = %w( noop verbose )
|
OPT_TABLE['safe_unlink'] = [:noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: force noop verbose secure
|
# Options: force noop verbose secure
|
||||||
|
@ -594,7 +595,7 @@ module FileUtils
|
||||||
# See also #remove_entry_secure.
|
# See also #remove_entry_secure.
|
||||||
#
|
#
|
||||||
def rm_r(list, options = {})
|
def rm_r(list, options = {})
|
||||||
fu_check_options options, :force, :noop, :verbose, :secure
|
fu_check_options options, OPT_TABLE['rm_r']
|
||||||
# options[:secure] = true unless options.key?(:secure)
|
# options[:secure] = true unless options.key?(:secure)
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message "rm -r#{options[:force] ? 'f' : ''} #{list.join ' '}" if options[:verbose]
|
fu_output_message "rm -r#{options[:force] ? 'f' : ''} #{list.join ' '}" if options[:verbose]
|
||||||
|
@ -609,7 +610,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :rm_r
|
module_function :rm_r
|
||||||
|
|
||||||
OPT_TABLE['rm_r'] = %w( noop verbose force secure )
|
OPT_TABLE['rm_r'] = [:force, :noop, :verbose, :secure]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose secure
|
# Options: noop verbose secure
|
||||||
|
@ -622,7 +623,7 @@ module FileUtils
|
||||||
# Read the documentation of #rm_r first.
|
# Read the documentation of #rm_r first.
|
||||||
#
|
#
|
||||||
def rm_rf(list, options = {})
|
def rm_rf(list, options = {})
|
||||||
fu_check_options options, :noop, :verbose, :secure
|
fu_check_options options, OPT_TABLE['rm_rf']
|
||||||
options = options.dup
|
options = options.dup
|
||||||
options[:force] = true
|
options[:force] = true
|
||||||
rm_r list, options
|
rm_r list, options
|
||||||
|
@ -633,7 +634,7 @@ module FileUtils
|
||||||
module_function :rmtree
|
module_function :rmtree
|
||||||
|
|
||||||
OPT_TABLE['rm_rf'] =
|
OPT_TABLE['rm_rf'] =
|
||||||
OPT_TABLE['rmtree'] = %w( noop verbose secure )
|
OPT_TABLE['rmtree'] = [:noop, :verbose, :secure]
|
||||||
|
|
||||||
#
|
#
|
||||||
# This method removes a file system entry +path+. +path+ shall be a
|
# This method removes a file system entry +path+. +path+ shall be a
|
||||||
|
@ -813,16 +814,17 @@ module FileUtils
|
||||||
module_function :compare_stream
|
module_function :compare_stream
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: mode noop verbose
|
# Options: mode preserve noop verbose
|
||||||
#
|
#
|
||||||
# If +src+ is not same as +dest+, copies it and changes the permission
|
# If +src+ is not same as +dest+, copies it and changes the permission
|
||||||
# mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
|
# mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
|
||||||
|
# This method removes destination before copy.
|
||||||
#
|
#
|
||||||
# FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
|
# FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
|
||||||
# FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
|
# FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
|
||||||
#
|
#
|
||||||
def install(src, dest, options = {})
|
def install(src, dest, options = {})
|
||||||
fu_check_options options, :mode, :preserve, :noop, :verbose
|
fu_check_options options, OPT_TABLE['install']
|
||||||
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
fu_each_src_dest(src, dest) do |s, d|
|
fu_each_src_dest(src, dest) do |s, d|
|
||||||
|
@ -837,7 +839,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :install
|
module_function :install
|
||||||
|
|
||||||
OPT_TABLE['install'] = %w( noop verbose preserve mode )
|
OPT_TABLE['install'] = [:mode, :preserve, :noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
|
@ -850,7 +852,7 @@ module FileUtils
|
||||||
# FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
|
# FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
|
||||||
#
|
#
|
||||||
def chmod(mode, list, options = {})
|
def chmod(mode, list, options = {})
|
||||||
fu_check_options options, :noop, :verbose
|
fu_check_options options, OPT_TABLE['chmod']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]
|
fu_output_message sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
|
@ -860,7 +862,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :chmod
|
module_function :chmod
|
||||||
|
|
||||||
OPT_TABLE['chmod'] = %w( noop verbose )
|
OPT_TABLE['chmod'] = [:noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose force
|
# Options: noop verbose force
|
||||||
|
@ -871,7 +873,7 @@ module FileUtils
|
||||||
# FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
|
# FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
|
||||||
#
|
#
|
||||||
def chmod_R(mode, list, options = {})
|
def chmod_R(mode, list, options = {})
|
||||||
fu_check_options options, :noop, :verbose, :force
|
fu_check_options options, OPT_TABLE['chmod_R']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message sprintf('chmod -R%s %o %s',
|
fu_output_message sprintf('chmod -R%s %o %s',
|
||||||
(options[:force] ? 'f' : ''),
|
(options[:force] ? 'f' : ''),
|
||||||
|
@ -889,7 +891,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :chmod_R
|
module_function :chmod_R
|
||||||
|
|
||||||
OPT_TABLE['chmod_R'] = %w( noop verbose )
|
OPT_TABLE['chmod_R'] = [:noop, :verbose, :force]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
|
@ -904,7 +906,7 @@ module FileUtils
|
||||||
# FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true
|
# FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true
|
||||||
#
|
#
|
||||||
def chown(user, group, list, options = {})
|
def chown(user, group, list, options = {})
|
||||||
fu_check_options options, :noop, :verbose
|
fu_check_options options, OPT_TABLE['chown']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message sprintf('chown %s%s',
|
fu_output_message sprintf('chown %s%s',
|
||||||
[user,group].compact.join(':') + ' ',
|
[user,group].compact.join(':') + ' ',
|
||||||
|
@ -918,7 +920,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :chown
|
module_function :chown
|
||||||
|
|
||||||
OPT_TABLE['chown'] = %w( noop verbose )
|
OPT_TABLE['chown'] = [:noop, :verbose]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose force
|
# Options: noop verbose force
|
||||||
|
@ -933,7 +935,7 @@ module FileUtils
|
||||||
# FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true
|
# FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true
|
||||||
#
|
#
|
||||||
def chown_R(user, group, list, options = {})
|
def chown_R(user, group, list, options = {})
|
||||||
fu_check_options options, :noop, :verbose, :force
|
fu_check_options options, OPT_TABLE['chown_R']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message sprintf('chown -R%s %s%s',
|
fu_output_message sprintf('chown -R%s %s%s',
|
||||||
(options[:force] ? 'f' : ''),
|
(options[:force] ? 'f' : ''),
|
||||||
|
@ -955,7 +957,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :chown_R
|
module_function :chown_R
|
||||||
|
|
||||||
OPT_TABLE['chown_R'] = %w( noop verbose )
|
OPT_TABLE['chown_R'] = [:noop, :verbose, :force]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'etc'
|
require 'etc'
|
||||||
|
@ -1003,7 +1005,7 @@ module FileUtils
|
||||||
# FileUtils.touch Dir.glob('*.c'); system 'make'
|
# FileUtils.touch Dir.glob('*.c'); system 'make'
|
||||||
#
|
#
|
||||||
def touch(list, options = {})
|
def touch(list, options = {})
|
||||||
fu_check_options options, :noop, :verbose
|
fu_check_options options, OPT_TABLE['touch']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
fu_output_message "touch #{list.join ' '}" if options[:verbose]
|
fu_output_message "touch #{list.join ' '}" if options[:verbose]
|
||||||
return if options[:noop]
|
return if options[:noop]
|
||||||
|
@ -1020,7 +1022,7 @@ module FileUtils
|
||||||
end
|
end
|
||||||
module_function :touch
|
module_function :touch
|
||||||
|
|
||||||
OPT_TABLE['touch'] = %w( noop verbose )
|
OPT_TABLE['touch'] = [:noop, :verbose]
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -1413,10 +1415,10 @@ module FileUtils
|
||||||
end
|
end
|
||||||
private_module_function :fu_have_st_ino?
|
private_module_function :fu_have_st_ino?
|
||||||
|
|
||||||
def fu_check_options(options, *optdecl) #:nodoc:
|
def fu_check_options(options, optdecl) #:nodoc:
|
||||||
h = options.dup
|
h = options.dup
|
||||||
optdecl.each do |name|
|
optdecl.each do |opt|
|
||||||
h.delete name
|
h.delete opt
|
||||||
end
|
end
|
||||||
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
|
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
|
||||||
end
|
end
|
||||||
|
@ -1457,7 +1459,7 @@ module FileUtils
|
||||||
# p FileUtils.options #=> ["noop", "force", "verbose", "preserve", "mode"]
|
# p FileUtils.options #=> ["noop", "force", "verbose", "preserve", "mode"]
|
||||||
#
|
#
|
||||||
def FileUtils.options
|
def FileUtils.options
|
||||||
OPT_TABLE.values.flatten.uniq
|
OPT_TABLE.values.flatten.uniq.map {|sym| sym.to_s }
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1469,7 +1471,7 @@ module FileUtils
|
||||||
#
|
#
|
||||||
def FileUtils.have_option?(mid, opt)
|
def FileUtils.have_option?(mid, opt)
|
||||||
li = OPT_TABLE[mid.to_s] or raise ArgumentError, "no such method: #{mid}"
|
li = OPT_TABLE[mid.to_s] or raise ArgumentError, "no such method: #{mid}"
|
||||||
li.include?(opt.to_s)
|
li.include?(opt)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1478,7 +1480,7 @@ module FileUtils
|
||||||
# p FileUtils.options(:rm) #=> ["noop", "verbose", "force"]
|
# p FileUtils.options(:rm) #=> ["noop", "verbose", "force"]
|
||||||
#
|
#
|
||||||
def FileUtils.options_of(mid)
|
def FileUtils.options_of(mid)
|
||||||
OPT_TABLE[mid.to_s]
|
OPT_TABLE[mid.to_s].map {|sym| sym.to_s }
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1487,7 +1489,7 @@ module FileUtils
|
||||||
# p FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"]
|
# p FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"]
|
||||||
#
|
#
|
||||||
def FileUtils.collect_method(opt)
|
def FileUtils.collect_method(opt)
|
||||||
OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt.to_s) }
|
OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
|
||||||
end
|
end
|
||||||
|
|
||||||
METHODS = singleton_methods() - %w( private_module_function
|
METHODS = singleton_methods() - %w( private_module_function
|
||||||
|
@ -1502,7 +1504,7 @@ module FileUtils
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@fileutils_output = $stderr
|
@fileutils_output = $stderr
|
||||||
@fileutils_label = ''
|
@fileutils_label = ''
|
||||||
::FileUtils.collect_method('verbose').each do |name|
|
::FileUtils.collect_method(:verbose).each do |name|
|
||||||
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||||
def #{name}(*args)
|
def #{name}(*args)
|
||||||
super(*fu_update_option(args, :verbose => true))
|
super(*fu_update_option(args, :verbose => true))
|
||||||
|
@ -1527,7 +1529,7 @@ module FileUtils
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@fileutils_output = $stderr
|
@fileutils_output = $stderr
|
||||||
@fileutils_label = ''
|
@fileutils_label = ''
|
||||||
::FileUtils.collect_method('noop').each do |name|
|
::FileUtils.collect_method(:noop).each do |name|
|
||||||
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||||
def #{name}(*args)
|
def #{name}(*args)
|
||||||
super(*fu_update_option(args, :noop => true))
|
super(*fu_update_option(args, :noop => true))
|
||||||
|
@ -1553,7 +1555,7 @@ module FileUtils
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@fileutils_output = $stderr
|
@fileutils_output = $stderr
|
||||||
@fileutils_label = ''
|
@fileutils_label = ''
|
||||||
::FileUtils.collect_method('noop').each do |name|
|
::FileUtils.collect_method(:noop).each do |name|
|
||||||
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||||
def #{name}(*args)
|
def #{name}(*args)
|
||||||
super(*fu_update_option(args, :noop => true, :verbose => true))
|
super(*fu_update_option(args, :noop => true, :verbose => true))
|
||||||
|
|
Loading…
Reference in a new issue