Module: Tid::Console
- Defined in:
- lib/tid/console.rb
Class Method Summary collapse
- .cmd(str, env = {}) ⇒ Object
- .debug? ⇒ Boolean
- .default_env ⇒ Object
- .show_cmd(str, env) ⇒ Object
- .show_cmd_result(out, err, status) ⇒ Object
Class Method Details
.cmd(str, env = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/tid/console.rb', line 17 def cmd(str, env = {}) env = default_env.merge(env) show_cmd(str, env) if debug? out, err, status = Open3.capture3(env, str) show_cmd_result(out, err, status) if debug? return out, err, status end |
.debug? ⇒ Boolean
25 26 27 |
# File 'lib/tid/console.rb', line 25 def debug? !!ENV['DEBUG'] end |
.default_env ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/tid/console.rb', line 7 def default_env env = if Boot2docker.have? Boot2docker.env else {} end env.merge!(Tid.env) unless Tid.env.nil? env end |
.show_cmd(str, env) ⇒ Object
29 30 31 32 |
# File 'lib/tid/console.rb', line 29 def show_cmd(str, env) puts "\n # #{str}".color(:blue) env.each { |k,v| puts " ENV['#{k}'] = #{v}" } end |
.show_cmd_result(out, err, status) ⇒ Object
34 35 36 37 38 |
# File 'lib/tid/console.rb', line 34 def show_cmd_result(out, err, status) puts "#{out}".chomp.gsub(/^(.*)/, ' \1').color(:green) unless out.empty? puts "#{err}".chomp.gsub(/^(.*)/, ' \1').color(:red) unless err.empty? puts " exit status: #{status.exitstatus}".color(:yellow) end |