Sha256: 5b33c1536f173af5a6b9bbeb4456e4ad87f94b43f477f1ad8a48010d844cf48c
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
require 'toolrack' require 'tempfile' module Hitcher module CommandRunner include Antrapol::ToolRack::ConditionUtils # 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) puts cmd #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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
Hitcher-0.1.0 | lib/hitcher/command_runner.rb |