Module: Tinet::Shell

Included in:
Command::Base
Defined in:
lib/tinet/shell.rb

Defined Under Namespace

Classes: DummyStatus

Instance Method Summary collapse

Instance Method Details

#sh(command, dry_run: false, print: false, continue: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tinet/shell.rb', line 16

def sh(command, dry_run: false, print: false, continue: false)
  if dry_run || print
    Tinet.logger.info command
  else
    Tinet.logger.debug command
  end

  return ['', '', DummyStatus.new(true)] if dry_run

  stdout, stderr, status = Open3.capture3(command)

  if !status.success? && !continue
    Tinet.logger.error "Command '#{command}' failed:"
    Tinet.logger.error "  #{stderr.chomp}" unless stderr.chomp.empty?
    exit(status.to_i)
  end

  [stdout.chomp, stderr.chomp, status]
end

#sudo(command) ⇒ Object



12
13
14
# File 'lib/tinet/shell.rb', line 12

def sudo(command)
  sh "sudo #{command}"
end