Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite of #213 - Commands will be printed only if they are executing on servers #284

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/capistrano/configuration/actions/invocation.rb
Expand Up @@ -159,18 +159,26 @@ def run(cmd, options={}, &block)
# use, but should instead be called indirectly, via #run or #parallel,
# or #invoke_command.
def run_tree(tree, options={}) #:nodoc:
# Build a list of log messages to show only if dry_run,
# or there are any servers available to execute the command
log_before_executing = []
show_logs = Proc.new {|logs| logs.each {|level, message| @logger.send(level, message)}}

if tree.branches.empty? && tree.fallback
logger.debug "executing #{tree.fallback}"
log_before_executing << [:debug, "executing #{tree.fallback}"]
elsif tree.branches.any?
logger.debug "executing multiple commands in parallel"
log_before_executing << [:debug, "executing multiple commands in parallel"]
tree.each do |branch|
logger.trace "-> #{branch}"
log_before_executing << [:trace, "-> #{branch}"]
end
else
raise ArgumentError, "attempt to execute without specifying a command"
end

return if dry_run || (debug && continue_execution(tree) == false)
if dry_run || (debug && continue_execution(tree) == false)
show_logs[log_before_executing]
return
end

options = add_default_command_options(options)

Expand All @@ -181,6 +189,7 @@ def run_tree(tree, options={}) #:nodoc:
end

execute_on_servers(options) do |servers|
show_logs[log_before_executing]
targets = servers.map { |s| sessions[s] }
Command.process(tree, targets, options.merge(:logger => logger))
end
Expand Down