Module: Simple::CLI::Helpers

Defined in:
lib/simple/cli/helpers.rb

Overview

Helpers are mixed into all CLI modules. They implement the following methods, mostly to help with integrating external commands:

  • sys

  • sys!

  • sh!

  • die!

Defined Under Namespace

Classes: Command

Instance Method Summary collapse

Instance Method Details

#die!(msg) ⇒ Object



12
13
14
15
# File 'lib/simple/cli/helpers.rb', line 12

def die!(msg)
  STDERR.puts msg
  exit 1
end

#sh!(cmd, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simple/cli/helpers.rb', line 17

def sh!(cmd, *args)
  command = Command.new(cmd, *args)
  result = command.sh
  command.check_success!
  first_line, more = result.split("\n", 2)
  if more == ""
    first_line
  else
    result
  end
end

#sys(cmd, *args) ⇒ Object



29
30
31
32
33
# File 'lib/simple/cli/helpers.rb', line 29

def sys(cmd, *args)
  command = Command.new(cmd, *args)
  command.run
  command.success?
end

#sys!(cmd, *args) ⇒ Object



35
36
37
38
39
40
# File 'lib/simple/cli/helpers.rb', line 35

def sys!(cmd, *args)
  command = Command.new(cmd, *args)
  command.run
  command.check_success!
  true
end