diff --git a/CHANGELOG.md b/CHANGELOG.md index 582c2231..9a06f55b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,11 +16,20 @@ gem "capistrano", :github => "capistrano/capistrano" ## master -https://github.com/capistrano/capistrano/compare/v3.8.1...HEAD +https://github.com/capistrano/capistrano/compare/v3.8.2...HEAD * Your contribution here! * Updated `deploy:cleanup` to continue rotating the releases and skip the invalid directory names instead of skipping the whole rotation of releases. The warning message has changed slightly due to the change of behavior. +* [#1911](https://github.com/capistrano/capistrano/pull/1911): Add Capistrano::DSL#invoke! for repetetive tasks + +### Breaking changes: + +* None + +### Other changes: + +* None ## `3.8.2` (2017-06-16) diff --git a/lib/capistrano/dsl.rb b/lib/capistrano/dsl.rb index d7519dd6..31a81953 100644 --- a/lib/capistrano/dsl.rb +++ b/lib/capistrano/dsl.rb @@ -19,13 +19,19 @@ module Capistrano colors = SSHKit::Color.new($stderr) $stderr.puts colors.colorize("Skipping task `#{task_name}'.", :yellow) $stderr.puts "Capistrano tasks may only be invoked once. Since task `#{task}' was previously invoked, invoke(\"#{task_name}\") at #{file}:#{line} will be skipped." - $stderr.puts "If you really meant to run this task again, first call Rake::Task[\"#{task_name}\"].reenable" + $stderr.puts "If you really meant to run this task again, use invoke!(\"#{task_name}\")" $stderr.puts colors.colorize("THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.", :red) $stderr.puts colors.colorize("https://github.com/capistrano/capistrano/issues/1686", :red) end task.invoke(*args) end + def invoke!(task_name, *args) + task = Rake::Task[task_name] + task.reenable + task.invoke(*args) + end + def t(key, options={}) I18n.t(key, options.merge(scope: :capistrano)) end diff --git a/spec/lib/capistrano/dsl_spec.rb b/spec/lib/capistrano/dsl_spec.rb index f7b44229..c58b0df6 100644 --- a/spec/lib/capistrano/dsl_spec.rb +++ b/spec/lib/capistrano/dsl_spec.rb @@ -71,13 +71,54 @@ module Capistrano end describe "#invoke" do - it "will print a message on stderr, when reinvoking task" do - Rake::Task.define_task("some_task") + context "reinvoking" do + it "will not reenable invoking task" do + counter = 0 - dsl.invoke("some_task") - expect do - dsl.invoke("some_task") - end.to output(/.*Capistrano tasks may only be invoked once.*/).to_stderr + Rake::Task.define_task("A") do + counter += 1 + end + + expect do + dsl.invoke("A") + dsl.invoke("A") + end.to change { counter }.by(1) + end + + it "will print a message on stderr" do + Rake::Task.define_task("B") + + expect do + dsl.invoke("B") + dsl.invoke("B") + end.to output(/If you really meant to run this task again, use invoke!/).to_stderr + end + end + end + + describe "#invoke!" do + context "reinvoking" do + it "will reenable invoking task" do + counter = 0 + + Rake::Task.define_task("C") do + counter += 1 + end + + expect do + dsl.invoke!("C") + dsl.invoke!("C") + end.to change { counter }.by(2) + end + + it "will not print a message on stderr" do + Rake::Task.define_task("D") + + expect do + dsl.invoke!("D") + dsl.invoke!("D") + end.to_not output(/If you really meant to run this task again, use invoke!/).to_stderr + end end end end