require 'toolrack' require 'tempfile' require_relative 'user_prompt' module Hitcher module CommandRunner include Antrapol::ToolRack::ConditionUtils include Hitcher::UserPrompt # functions to assist in running a command line app class TerminalNotDefined < StandardError; end def run_in_new_terminal(cmd, &block) term = Hitcher::Global.instance.config.terminal if not_empty?(term) notice "\nCommand to run in new terminal app: #{cmd}\n\n" #tf = Tempfile.new #File.open(tf,"w") do |f| # f.write "#!/bin/sh" # f.write cmd # f.write "read -p \"Any key\"" #end `#{term} -x "#{cmd}"` #`#{term} -x sh -c "./#{tf}; bash"` term else raise TerminalNotDefined, "Terminal is not defined in the config file" end end # run_in_new_terminal def run_command(cmd, &block) out = [] err = [] c = TTY::Command.new # raise TTY::Command::ExitError if command exit code is non-zero c.run(cmd) do |o,e| out << o if not_empty?(o) err << e if not_empty?(e) end if not_empty?(err) [false, out, err] else [true, out, err] end end # run_command end # module CommandRunner end