Skip to content

Commit

Permalink
Introduce runtime(command) method
Browse files Browse the repository at this point in the history
Reduce complexity in the format_command_completion_status method
  • Loading branch information
robd committed May 26, 2015
1 parent 59a0296 commit 3872f41
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/airbrussh/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def write_command(command)
end

if command.finished?
status = format_command_completion_status(command)
print_line " #{status}"
print_line " #{format_exit_status(command)} #{runtime(command)}"
end
end

Expand All @@ -148,22 +147,21 @@ def std_stream_lines(command, stream)
end
end

def format_command_completion_status(command)
def format_exit_status(command)
user = command.user { command.host.user }
host = command.host.to_s
user_at_host = [user, host].join("@")
number = number(command)

status = \
if command.failure?
red("✘ #{number} #{user_at_host} (see #{@log_file} for details)")
else
green("✔ #{number} #{user_at_host}")
end

runtime = light_black(format("%5.3fs", command.runtime))
if command.failure?
red("✘ #{number} #{user_at_host} (see #{@log_file} for details)")
else
green("✔ #{number} #{user_at_host}")
end
end

status + " " + runtime
def runtime(command)
light_black(format("%5.3fs", command.runtime))
end

def clock
Expand Down

0 comments on commit 3872f41

Please sign in to comment.