Sha256: 56236d5925b0f7ee9e63ae85f56a35788f02ec2340ce37c35351cf09fd9c8dad
Contents?: true
Size: 1.22 KB
Versions: 10
Compression:
Stored size: 1.22 KB
Contents
module Kubes::Util module Sh include Kubes::Logging def sh(command, options={}) mute = options[:mute] show_command = options[:show_command].nil? ? !mute : options[:show_command] exit_on_fail = options[:exit_on_fail].nil? ? true : options[:exit_on_fail] # Logger::DEBUG = 0 # Logger::INFO = 1 if logger.level <= Logger::DEBUG mute = false show_command = true end env = options[: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) exit $?.exitstatus if exit_on_fail end success end def sh_capture(command, options={}) exit_on_fail = options[:exit_on_fail].nil? ? true : options[:exit_on_fail] logger.info "=> #{command}" if options[:show_command] out = `#{command}`.strip unless $?.success? logger.error "ERROR: running #{command}".color(:red) exit $?.exitstatus if exit_on_fail end out end end end
Version data entries
10 entries across 10 versions & 1 rubygems