Sha256: c578a0b571b555b3f703da05d670507874f7c527accfcf4933e8a84524a564cf

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

module Jets::Util
  module Sh
    def sh(command, options = {})
      quiet = options[:quiet]
      on_fail = options[:on_fail] || :raise

      puts "=> #{command}" unless quiet
      system(command)
      success = $?.success?

      case on_fail
      when :raise
        raise Jets::Error.new("Command failed: #{command}\n#{caller(1..1).first}") unless success
      when :exit
        unless success
          if quiet
            abort("Command failed: #{command}\n")
          else
            abort("Command failed: #{command}\n#{caller.join("\n")}")
          end
        end
      end

      success
    end

    def quiet_sh(command, options = {})
      options = options.merge(quiet: true) unless ENV["JETS_DEBUG"]
      sh(command, options)
    end

    def capture(command)
      out = `#{command}`.strip
      raise Jets::Error.new("Command failed: #{command}\n#{caller(1..1).first}") unless $?.success?
      out
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/util/sh.rb
jets-6.0.4 lib/jets/util/sh.rb
jets-6.0.3 lib/jets/util/sh.rb
jets-6.0.2 lib/jets/util/sh.rb