Class: Rlt::Utils::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/rlt/utils/shell.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Shell

Returns a new instance of Shell.



8
9
10
# File 'lib/rlt/utils/shell.rb', line 8

def initialize(opts = {})
  @cmd = TTY::Command.new(printer: printer(opts), pty: true, dry_run: Rlt.debug)
end

Instance Method Details

#current_userObject



24
25
26
# File 'lib/rlt/utils/shell.rb', line 24

def current_user
  ENV['USER'] || ENV['USERNAME']
end

#run(*args) ⇒ Object



12
13
14
15
16
# File 'lib/rlt/utils/shell.rb', line 12

def run(*args)
  result = @cmd.run(*args, user: current_user)
  puts '' if Rlt.debug
  result
end

#run_safely(*args) ⇒ Object



18
19
20
21
22
# File 'lib/rlt/utils/shell.rb', line 18

def run_safely(*args)
  result = @cmd.run!(*args, user: current_user)
  puts '' if Rlt.debug
  result.success?
end