diff --git a/lib/rake/clean.rb b/lib/rake/clean.rb index 5af44015e..b52e832a9 100644 --- a/lib/rake/clean.rb +++ b/lib/rake/clean.rb @@ -28,10 +28,10 @@ def cleanup_files(file_names) end end - def cleanup(file_name, opts={}) + def cleanup(file_name, **opts) begin opts = { verbose: Rake.application.options.trace }.merge(opts) - rm_r file_name, opts + rm_r file_name, **opts rescue StandardError => ex puts "Failed to remove #{file_name}: #{ex}" unless file_already_gone?(file_name) end diff --git a/lib/rake/file_utils.rb b/lib/rake/file_utils.rb index 00c9c9dca..e979eedb2 100644 --- a/lib/rake/file_utils.rb +++ b/lib/rake/file_utils.rb @@ -97,12 +97,11 @@ def set_verbose_option(options) # :nodoc: # Example: # ruby %{-pe '$_.upcase!' 1 - sh(*([RUBY] + args + [options]), &block) + sh(RUBY, *args, **options, &block) else - sh("#{RUBY} #{args.first}", options, &block) + sh("#{RUBY} #{args.first}", **options, &block) end end @@ -110,15 +109,15 @@ def ruby(*args, &block) # Attempt to do a normal file link, but fall back to a copy if the link # fails. - def safe_ln(*args) + def safe_ln(*args, **options) if LN_SUPPORTED[0] begin - return ln(*args) + return options.empty? ? ln(*args) : ln(*args, **options) rescue StandardError, NotImplementedError LN_SUPPORTED[0] = false end end - cp(*args) + options.empty? ? cp(*args) : cp(*args, **options) end # Split a file path into individual directory names. diff --git a/lib/rake/file_utils_ext.rb b/lib/rake/file_utils_ext.rb index bf558b749..e91ad595f 100644 --- a/lib/rake/file_utils_ext.rb +++ b/lib/rake/file_utils_ext.rb @@ -23,19 +23,18 @@ class << self opts = FileUtils.options_of name default_options = [] if opts.include?("verbose") - default_options << ":verbose => FileUtilsExt.verbose_flag" + default_options << "verbose: FileUtilsExt.verbose_flag" end if opts.include?("noop") - default_options << ":noop => FileUtilsExt.nowrite_flag" + default_options << "noop: FileUtilsExt.nowrite_flag" end next if default_options.empty? module_eval(<<-EOS, __FILE__, __LINE__ + 1) - def #{name}( *args, &block ) - super( - *rake_merge_option(args, - #{default_options.join(', ')} - ), &block) + def #{name}(*args, **options, &block) + super(*args, + #{default_options.join(', ')}, + **options, &block) end EOS end @@ -113,16 +112,6 @@ def when_writing(msg=nil) end end - # Merge the given options with the default values. - def rake_merge_option(args, defaults) - if Hash === args.last - defaults.update(args.last) - args.pop - end - args.push defaults - args - end - # Send the message to the default rake output (which is $stderr). def rake_output_message(message) $stderr.puts(message) diff --git a/lib/rake/task.rb b/lib/rake/task.rb index 7629732f6..80824f37b 100644 --- a/lib/rake/task.rb +++ b/lib/rake/task.rb @@ -274,7 +274,11 @@ def execute(args=nil) end application.trace "** Execute #{name}" if application.options.trace application.enhance_with_matching_rule(name) if @actions.empty? - @actions.each { |act| act.call(self, args) } + if opts = Hash.try_convert(args) and !opts.empty? + @actions.each { |act| act.call(self, args, **opts)} + else + @actions.each { |act| act.call(self, args)} + end end # Is this task needed? diff --git a/test/test_rake_file_utils.rb b/test/test_rake_file_utils.rb index 7e9674fdc..ebedd56b2 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -39,6 +39,22 @@ def test_rm_filelist refute File.exist?("b") end + def test_rm_nowrite + create_file("a") + nowrite(true) { + rm_rf "a" + } + assert File.exist?("a") + nowrite(false) { + rm_rf "a", noop: true + } + assert File.exist?("a") + nowrite(true) { + rm_rf "a", noop: false + } + refute File.exist?("a") + end + def test_ln open("a", "w") { |f| f.puts "TEST_LN" }