Sha256: 0c2c707415273e9d0d14e7e5fa612f614c8618df28173f34eae42c9827025179

Contents?: true

Size: 1.19 KB

Versions: 31

Compression:

Stored size: 1.19 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.debug "=> #{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

31 entries across 31 versions & 1 rubygems

Version Path
kubes-0.8.10 lib/kubes/util/sh.rb
kubes-0.8.9 lib/kubes/util/sh.rb
kubes-0.8.8 lib/kubes/util/sh.rb
kubes-0.8.7 lib/kubes/util/sh.rb
kubes-0.8.6 lib/kubes/util/sh.rb
kubes-0.8.5 lib/kubes/util/sh.rb
kubes-0.8.4 lib/kubes/util/sh.rb
kubes-0.8.3 lib/kubes/util/sh.rb
kubes-0.8.2 lib/kubes/util/sh.rb
kubes-0.8.1 lib/kubes/util/sh.rb
kubes-0.8.0 lib/kubes/util/sh.rb
kubes-0.7.10 lib/kubes/util/sh.rb
kubes-0.7.9 lib/kubes/util/sh.rb
kubes-0.7.8 lib/kubes/util/sh.rb
kubes-0.7.7 lib/kubes/util/sh.rb
kubes-0.7.6 lib/kubes/util/sh.rb
kubes-0.7.5 lib/kubes/util/sh.rb
kubes-0.7.4 lib/kubes/util/sh.rb
kubes-0.7.3 lib/kubes/util/sh.rb
kubes-0.7.2 lib/kubes/util/sh.rb