Class: Gerrit::Cli::ShellRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/gerrit/cli/shell_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ ShellRunner

Returns a new instance of ShellRunner.



11
12
13
# File 'lib/gerrit/cli/shell_runner.rb', line 11

def initialize(logger)
  @logger = logger || Logger.new(STDOUT)
end

Instance Method Details

#capture!(command) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gerrit/cli/shell_runner.rb', line 25

def capture!(command)
  @logger.debug("+ #{command}")

  out = `#{command}`
  unless $?.success?
    st = $?.exitstatus
    emsg = "Command '#{command}' exited with non-zero status (#{st})."
    raise Gerrit::Cli::Error.new(emsg)
  end

  out
end

#system!(command) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/gerrit/cli/shell_runner.rb', line 15

def system!(command)
  @logger.debug("+ #{command}")

  unless system(command)
    st = $?.exitstatus
    emsg = "Command '#{command}' exited with non-zero status (#{st})."
    raise Gerrit::Cli::Error.new(emsg)
  end
end