Class: Sidedock::CLI

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

Direct Known Subclasses

DockerCLI, MachineCLI

Instance Method Summary collapse

Constructor Details

#initialize(default_options = '') ⇒ CLI

Returns a new instance of CLI.



7
8
9
# File 'lib/sidedock/cli.rb', line 7

def initialize(default_options = '')
  @default_options = default_options
end

Instance Method Details

#command_runnerObject



19
20
21
22
23
24
25
# File 'lib/sidedock/cli.rb', line 19

def command_runner
  if Sidedock.configuration.debug
    debug_command_runner
  else
    quiet_command_runner
  end
end

#debug_command_runnerObject



27
28
29
# File 'lib/sidedock/cli.rb', line 27

def debug_command_runner
  @debug_command_runner ||= TTY::Command.new
end

#execute(command) ⇒ Object



12
13
14
15
16
17
# File 'lib/sidedock/cli.rb', line 12

def execute(command)
  full_command = "#{program} #{@default_options} #{command}"
  stdout, stderr = command_runner.run full_command
  raise "`#{command}` failed" if stderr.present?
  stdout.strip
end

#quiet_command_runnerObject



31
32
33
# File 'lib/sidedock/cli.rb', line 31

def quiet_command_runner
  @quiet_command_runner ||= TTY::Command.new printer: :null
end