Class: Ruby::Nginx::Commands::TerminalCommand
- Inherits:
-
Object
- Object
- Ruby::Nginx::Commands::TerminalCommand
- Includes:
- Helpers::PromptHelper, Helpers::SudoHelper
- Defined in:
- lib/ruby/nginx/commands/terminal_command.rb
Direct Known Subclasses
AddHostMapping, CreateMkcertCertificate, InstallMkcert, InstallNginx, NginxOptions, NginxVersion, RemoveHostMapping, SetupMkcert, SetupNginx, StartNginx, StopNginx, ValidateNginxConfig
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#error_type ⇒ Object
readonly
Returns the value of attribute error_type.
-
#printer ⇒ Object
readonly
Returns the value of attribute printer.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(cmd:, user: nil, raise: nil, printer: :null) ⇒ TerminalCommand
constructor
A new instance of TerminalCommand.
- #run ⇒ Object
Methods included from Helpers::SudoHelper
Methods included from Helpers::PromptHelper
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
#cmd ⇒ Object (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_type ⇒ Object (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 |
#printer ⇒ Object (readonly)
Returns the value of attribute printer.
14 15 16 |
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14 def printer @printer end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
14 15 16 |
# File 'lib/ruby/nginx/commands/terminal_command.rb', line 14 def result @result end |
#user ⇒ Object (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
#run ⇒ Object
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 |