Class: RightConf::Command
- Inherits:
-
Object
- Object
- RightConf::Command
- Includes:
- ProgressReporter, Singleton
- Defined in:
- lib/rconf/command.rb
Instance Method Summary collapse
-
#execute(command, *args) ⇒ Object
Execute given command with given arguments.
-
#execute_linux(command, *args) ⇒ Object
(also: #execute_darwin)
Execute given command on *nix systems.
-
#execute_windows(command, *args) ⇒ Object
Execute given command on Windows systems.
-
#set_prefix(prefix) ⇒ Object
Set prefix to be used for all commands.
Methods included from ProgressReporter
included, report_to_file, report_to_stdout
Methods included from Singleton
Instance Method Details
#execute(command, *args) ⇒ Object
Execute given command with given arguments
Parameters
- command(String)
-
Command to run
- args(Array)
-
Command arguments
Return
- result(CommandResult)
-
Result of execution (output and exit status)
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rconf/command.rb', line 29 def execute(command, *args) opts = {} if !args.empty? && args[-1].is_a?(Hash) opts = args[-1] args = args[0..-2] end res = Platform.dispatch(command, *args) { :execute } if !res.success? && msg = opts[:abort_on_failure] report_fatal("#{msg}: '#{command} #{args.join(' ')}' returned\n#{res.output}") end res end |
#execute_linux(command, *args) ⇒ Object Also known as: execute_darwin
Execute given command on *nix systems
Parameters
- command(String)
-
Command name
- params(Array)
-
List of parameters to pass to command
Return
- result(CommandResult)
-
Result of execution (output and exit status)
50 51 52 53 |
# File 'lib/rconf/command.rb', line 50 def execute_linux(command, *args) out = `#{@prefix} #{Shellwords.join([command, *args])} 2>&1` result = CommandResult.new(out, $?.exitstatus) end |
#execute_windows(command, *args) ⇒ Object
Execute given command on Windows systems
Parameters
- command(String)
-
Command name
- params(Array)
-
List of parameters to pass to command
Return
- result(CommandResult)
-
Result of execution (output and exit status)
64 65 66 |
# File 'lib/rconf/command.rb', line 64 def execute_windows(command, *args) raise 'TBD!' end |
#set_prefix(prefix) ⇒ Object
Set prefix to be used for all commands
Parameters
- prefix(String)
-
Commands prefix
Return
- true
-
Always return true
75 76 77 78 |
# File 'lib/rconf/command.rb', line 75 def set_prefix(prefix) @prefix = prefix true end |