module GClouder::Shell

Public Class Methods

included(klass) click to toggle source
# File lib/gclouder/shell.rb, line 9
def self.included(klass)
  klass.extend Shell
end

Public Instance Methods

shell(command, failure: true, silent: false) click to toggle source
# File lib/gclouder/shell.rb, line 13
def shell(command, failure: true, silent: false)
  stdout, stderr, status, failed = run(command)

  if (GClouder.cli_args[:debug] || failed) && !silent
    header(command)
    dump_fds(stdout, stderr)
  end

  if !failed && silent
    return true
  end

  if failed && !failure
    return false
  end

  if failed && silent
    return false
  end

  if failed && !silent
    footer(status)
  end

  if silent
    return
  end

  stdout
end

Private Instance Methods

dump(fd) click to toggle source
# File lib/gclouder/shell.rb, line 56
def dump(fd)
  return if fd.empty?
  info fd
end
dump_fds(stdout, stderr) click to toggle source
# File lib/gclouder/shell.rb, line 51
def dump_fds(stdout, stderr)
  dump(stdout)
  dump(stderr)
end
header(command) click to toggle source
# File lib/gclouder/shell.rb, line 46
def header(command)
  info
  info "# #{command}"
end
run(command) click to toggle source
# File lib/gclouder/shell.rb, line 65
def run(command)
  stdout, stderr, status = Open3.capture3(command)
  failed = status.to_i > 0
  [stdout, stderr, status, failed]
end