Class: Train::Extras::LinuxCommand
- Inherits:
-
CommandWrapperBase
- Object
- CommandWrapperBase
- Train::Extras::LinuxCommand
- Defined in:
- lib/train/extras/command_wrapper.rb
Overview
Wrap linux commands and add functionality like sudo.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(backend, options) ⇒ LinuxCommand
constructor
A new instance of LinuxCommand.
- #run(command) ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(backend, options) ⇒ LinuxCommand
Returns a new instance of LinuxCommand.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/train/extras/command_wrapper.rb', line 37 def initialize(backend, ) @backend = backend () @sudo = [:sudo] @sudo_options = [:sudo_options] @sudo_password = [:sudo_password] @sudo_command = [:sudo_command] @user = [:user] @prefix = build_prefix end |
Class Method Details
.active?(options) ⇒ Boolean
77 78 79 |
# File 'lib/train/extras/command_wrapper.rb', line 77 def self.active?() .is_a?(Hash) && [:sudo] end |
Instance Method Details
#run(command) ⇒ Object
73 74 75 |
# File 'lib/train/extras/command_wrapper.rb', line 73 def run(command) @prefix + command end |
#verify ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/train/extras/command_wrapper.rb', line 50 def verify res = @backend.run_command(run('echo')) return nil if res.exit_status == 0 rawerr = res.stdout + ' ' + res.stderr { 'Sorry, try again' => 'Wrong sudo password.', 'sudo: no tty present and no askpass program specified' => 'Sudo requires a password, please configure it.', 'sudo: command not found' => "Can't find sudo command. Please either install and "\ 'configure it on the target or deactivate sudo.', 'sudo: sorry, you must have a tty to run sudo' => 'Sudo requires a TTY. Please see the README on how to configure '\ 'sudo to allow for non-interactive usage.', }.each do |sudo, human| rawerr = human if rawerr.include? sudo end rawerr end |