Module: Dapp::Helper::Shellout

Includes:
Streaming
Included in:
Application, CLI::Build, Controller, DockerImage
Defined in:
lib/dapp/helper/shellout.rb

Overview

Shellout

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



36
37
38
# File 'lib/dapp/helper/shellout.rb', line 36

def self.included(base)
  base.extend(self)
end

Instance Method Details

#shellout(*args, log_verbose: false, **kwargs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dapp/helper/shellout.rb', line 7

def shellout(*args, log_verbose: false, **kwargs)
  do_shellout = proc do
    log_verbose = (log_verbose && cli_options[:log_verbose]) if defined? cli_options
    kwargs[:live_stream] ||= STDOUT if log_verbose
    ::Mixlib::ShellOut.new(*args, timeout: 3600, **kwargs).run_command
  end

  if defined? ::Bundler
    ::Bundler.with_clean_env { do_shellout.call }
  else
    do_shellout.call
  end
end

#shellout!(*args, log_verbose: false, log_time: false, **kwargs) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dapp/helper/shellout.rb', line 21

def shellout!(*args, log_verbose: false, log_time: false, **kwargs)
  stream = Stream.new
  log_time = defined?(cli_options) ? cli_options[:log_time] : log_time
  if log_verbose
    kwargs[:live_stream] = Proxy::Base.new(stream, STDOUT, with_time: log_time)
  else
    kwargs[:live_stdout] = Proxy::Base.new(stream, with_time: log_time)
  end
  kwargs[:live_stderr] = Proxy::Error.new(stream, with_time: log_time)
  shellout(*args, **kwargs).tap(&:error!)
rescue ::Mixlib::ShellOut::ShellCommandFailed => e
  raise Error::Shellout, code: Trivia.class_to_lowercase(e.class),
                         data: { stream: stream.show }
end