Sha256: 1f771444e9ec337d1c1020f98feb3b63f3a6710a3ea9abfcbcadfcb83408959b

Contents?: true

Size: 903 Bytes

Versions: 1

Compression:

Stored size: 903 Bytes

Contents

module Glb::Util
  module Sh
    def sh(command, options={})
      command.squish!
      if options[:sure_prompt]
        sure? <<~EOL.chomp
          Will run: #{command}
          Are you sure?
        EOL
      end

      exit_on_fail = options[:exit_on_fail].nil? ? true : options[:exit_on_fail]
      show_command = options[:show_command] != false

      puts "=> #{command}".color(:green) if show_command
      return if ENV['DRY_RUN']

      success = system(command)
      if !success && exit_on_fail
        puts "Command failed: #{command}"
        exit $?.exitstatus
      end
      success
    end

    def capture(command, options={})
      command.squish!
      puts "=> #{command}" unless options[:show_command] == false
      out = `#{command}`
      if $?.exitstatus != 0
        puts "Error running command: #{command}"
        exit $?.exitstatus
      end
      out
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glb-0.1.1 lib/glb/util/sh.rb