Class: Cocaine::CommandLine
- Inherits:
-
Object
- Object
- Cocaine::CommandLine
- Defined in:
- lib/cocaine/command_line.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(binary, params = "", options = {}) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #run ⇒ Object
Constructor Details
#initialize(binary, params = "", options = {}) ⇒ CommandLine
Returns a new instance of CommandLine.
7 8 9 10 11 12 13 14 15 |
# File 'lib/cocaine/command_line.rb', line 7 def initialize(binary, params = "", = {}) @binary = binary.dup @params = params.dup @options = .dup @logger = @options.delete(:logger) || self.class.logger @swallow_stderr = @options.delete(:swallow_stderr) @expected_outcodes = @options.delete(:expected_outcodes) @expected_outcodes ||= [0] end |
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/cocaine/command_line.rb', line 4 def logger @logger end |
.path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/cocaine/command_line.rb', line 4 def path @path end |
Instance Method Details
#command ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cocaine/command_line.rb', line 17 def command cmd = [] cmd << @binary cmd << interpolate(@params, @options) cmd << bit_bucket if @swallow_stderr cmd.join(" ").strip end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cocaine/command_line.rb', line 25 def run output = '' begin with_modified_path do @logger.info("\e[32mCommand\e[0m :: #{command}") if @logger output = self.class.send(:'`', command) end rescue Errno::ENOENT raise Cocaine::CommandNotFoundError end if $?.exitstatus == 127 raise Cocaine::CommandNotFoundError end unless @expected_outcodes.include?($?.exitstatus) raise Cocaine::ExitStatusError, "Command '#{command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}" end output end |