Sha256: 07783c439f56f41c3ffc6296cb98c9aa827b689fd10c2456f40585d2440281ce

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'term/ansicolor'
class String
  include Term::ANSIColor
end
require 'tabulo'
require 'fileutils'
require 'tmpdir'
require 'shellwords'
require 'infobar'

module Hackmac
  module Utils
    include FileUtils

    def x(cmd, verbose: true, busy: nil)
      prompt = cmd =~ /\A\s*sudo/ ? ?# : ?$
      cmd_output = "#{prompt} #{cmd}".color(27) + (verbose ? "" : " >/dev/null".yellow)
      output, result = nil, nil
      if busy
        infobar.busy(label: busy) {
          infobar.puts cmd_output
          output = `#{cmd} 2>&1`
          result = $?
        }
      else
        infobar.puts cmd_output
        output = `#{cmd} 2>&1`
        result = $?
      end
      if verbose
        infobar.puts output.italic
      end
      if result.success?
        infobar.puts "✅ Command succeded!".green
      else
        infobar.puts "⚠️  Command #{cmd.inspect} failed with exit status #{result.exitstatus}".on_red.white
        exit result.exitstatus
      end
      output
    end

    def ask(prompt)
      print prompt.bold.yellow
      gets =~ /\Ay/i
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackmac-1.7.0 lib/hackmac/utils.rb