Module: Kubes::Util::Sh
- Includes:
- Logging
- Included in:
- CLI::Exec, CLI::Logs, Docker::Strategy::Utils, Hooks::Runner, Kubectl, Kubectl, Kubectl::Batch, Kubectl::Fetch::Base
- Defined in:
- lib/kubes/util/sh.rb
Instance Method Summary collapse
Methods included from Logging
Instance Method Details
#sh(command, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kubes/util/sh.rb', line 5 def sh(command, ={}) mute = [:mute] show_command = [:show_command].nil? ? !mute : [:show_command] exit_on_fail = [:exit_on_fail].nil? ? true : [:exit_on_fail] # Logger::DEBUG = 0 # Logger::INFO = 1 if logger.level <= Logger::DEBUG mute = false show_command = true end env = [:env] || {} env.stringify_keys! command = "#{command}" if mute && !command.include?("2>&1") command = "#{command} > /dev/null 2>&1" end logger.info "=> #{command}" if show_command success = system(env, command) unless success logger.error "ERROR: running #{command}".color(:red) if exit_on_fail exit $?.exitstatus if exit_on_fail end success end |
#sh_capture(command, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kubes/util/sh.rb', line 33 def sh_capture(command, ={}) exit_on_fail = [:exit_on_fail].nil? ? true : [:exit_on_fail] logger.debug "=> #{command}" out = `#{command}`.strip unless $?.success? logger.error "ERROR: running #{command}".color(:red) exit $?.exitstatus if exit_on_fail end out end |