Class: Ruby::Nginx::Commands::TerminalCommand

Inherits:
Object
  • Object
show all
Includes:
Helpers::PromptHelper, Helpers::SudoHelper
Defined in:
lib/ruby/nginx/commands/terminal_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::SudoHelper

#sudoify

Methods included from Helpers::PromptHelper

#yes?

Constructor Details

#initialize(cmd:, user: nil, raise: nil, printer: :null) ⇒ TerminalCommand

Returns a new instance of TerminalCommand.



16
17
18
19
20
21
22
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 16

def initialize(cmd:, user: nil, raise: nil, printer: :null)
  @cmd = cmd
  @user = user
  @error_type = raise
  @printer = ENV["DEBUG"] ? :pretty : printer
  @result = nil
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



14
15
16
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14

def cmd
  @cmd
end

#error_typeObject (readonly)

Returns the value of attribute error_type.



14
15
16
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14

def error_type
  @error_type
end

#printerObject (readonly)

Returns the value of attribute printer.



14
15
16
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14

def printer
  @printer
end

#resultObject (readonly)

Returns the value of attribute result.



14
15
16
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14

def result
  @result
end

#userObject (readonly)

Returns the value of attribute user.



14
15
16
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14

def user
  @user
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 24

def run
  @result = TTY::Command.new(printer: printer).run!(cmd, user: user)
  raise @error_type, @result.err if error_type && @result.failure?

  @result
rescue Interrupt
  raise Ruby::Nginx::AbortError, "Operation aborted"
end