lib/straight_line/common/command.rb in straight_line-0.1.1.0 vs lib/straight_line/common/command.rb in straight_line-0.1.2.0

- old
+ new

@@ -14,31 +14,40 @@ @args << argument @args += args if args self end + def self.from_file(_file_name); end + def run(return_stderr = false) Dir.chdir working_dir do command_with_params = "#{@command} #{@args.join ' '}" if return_stderr res, status = Open3.capture2e command_with_params else res, stderr, status = Open3.capture3(command_with_params) end - unless status.exitstatus == 0 + unless status.exitstatus.zero? output = return_stderr ? res : "#{res}\n#{stderr}" raise ShellError, %(Command `#{command_with_params}` exited with status code: #{status.exitstatus}. Command outputted:\n #{output}) end - sub_res = '' - sub_res = @sub_commands.map do |sub_command| - sub_command.run return_stderr - end.join("\n") unless @sub_commands.empty? + sub_res = run_sub_commands return_stderr res + "\n" + sub_res end + end + + def run_sub_commands(return_stderr) + sub_res = '' + unless @sub_commands.empty? + sub_res = @sub_commands.map do |sub_command| + sub_command.run return_stderr + end.join("\n") + end + sub_res end def sub_command(command) unless command.is_a? Command raise ArgumentError, 'command must be of type straight_line/common/command'