lib/makit/command_runner.rb in makit-0.0.0 vs lib/makit/command_runner.rb in makit-0.0.1

- old
+ new

@@ -7,15 +7,16 @@ # This module provides classes for the Makit gem. module Makit # This class provide methods running commands. # class CommandRunner - attr_accessor :show_output_on_success, :log_to_artifacts + attr_accessor :show_output_on_success, :log_to_artifacts, :commands def initialize @show_output_on_success = false @log_to_artifacts = false + @commands = [] end def run(command_request) raise "Invalid command_request" unless command_request.is_a? Makit::V1::CommandRequest command = execute(command_request) @@ -33,10 +34,11 @@ else puts Makit::CommandRunner.get_command_summary(command) + " (#{command.duration.seconds} seconds)".colorize(:cyan) puts Makit::Humanize::indent_string(command.output, 2).colorize(:default) if show_output_on_success end + commands.push(command) command end def log_to_artifacts(command) dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands") @@ -158,11 +160,10 @@ (output, error, exit_code) = execute_command(command, command_request.directory, command_request.timeout) result.output = output.force_encoding("ASCII-8BIT") result.error = error.force_encoding("ASCII-8BIT") result.exit_code = exit_code.nil? ? 0 : exit_code - elapsed_time = Time.now - start seconds = elapsed_time.to_i nanos = ((elapsed_time - seconds) * 1_000_000_000).to_i result.duration = Google::Protobuf::Duration.new(seconds: seconds, nanos: nanos) @@ -225,13 +226,12 @@ symbol = Makit::Symbols.checkmark if !command.exit_code.nil? && command.exit_code.zero? symbol = Makit::Symbols.error if command.exit_code != 0 summary = "#{symbol} #{command.name.colorize(:yellow)} #{command.arguments.join(" ")}" if summary.length > 80 - summary = summary.to_lines(80,command.name.length+3) + summary = summary.to_lines(80, command.name.length + 3) end summary end - end # class CommandRunner end # module Makit