Module: Minfra::Cli::Common

Includes:
Logging
Included in:
Command, Kube
Defined in:
lib/minfra/cli/common.rb

Instance Method Summary collapse

Methods included from Logging

#debug, #deprecated, #error, #exit_error, #info, #warn

Instance Method Details

#run_cmd(cmd, type = :non_system, silence: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/minfra/cli/common.rb', line 10

def run_cmd(cmd, type = :non_system, silence: false)
  debug(cmd)
  case type
  when :exec
    Kernel.exec(cmd)
  when :bash
    res = system(%(bash -c "#{Array.new(cmd).join(' && ')}"))
    exit_error('failed!') unless res
    nil # no output!
  when :system
    res = system(cmd)
    exit_error('failed!') unless res
    nil # no output!
  else
    `#{cmd}` # with output!
  end
end