Class: Cucumber::Chef::Command
- Inherits:
-
Object
- Object
- Cucumber::Chef::Command
- Defined in:
- lib/cucumber/chef/command.rb
Instance Attribute Summary collapse
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Command
constructor
A new instance of Command.
- #knife(command, options = {}) ⇒ Object
- #run(command, options = {}) ⇒ Object
Constructor Details
#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Command
Returns a new instance of Command.
32 33 34 35 36 37 38 |
# File 'lib/cucumber/chef/command.rb', line 32 def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN) @stdout, @stderr, @stdin = stdout, stderr, stdin @stdout.sync = true if @stdout.respond_to?(:sync=) @knife = (Cucumber::Chef.locate(:file, "bin", "knife") rescue nil) @knife = "/usr/bin/env knife" unless @knife end |
Instance Attribute Details
#stderr ⇒ Object
Returns the value of attribute stderr.
28 29 30 |
# File 'lib/cucumber/chef/command.rb', line 28 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
28 29 30 |
# File 'lib/cucumber/chef/command.rb', line 28 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
28 29 30 |
# File 'lib/cucumber/chef/command.rb', line 28 def stdout @stdout end |
Instance Method Details
#knife(command, options = {}) ⇒ Object
66 67 68 69 |
# File 'lib/cucumber/chef/command.rb', line 66 def knife(command, ={}) knife_rb = File.(File.join(Dir.pwd, ".cucumber-chef", "knife.rb")) run("#{@knife} #{command.flatten.compact.join(" ")} -c #{knife_rb} --color -n", ) end |
#run(command, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cucumber/chef/command.rb', line 42 def run(command, ={}) = { :exit_code => 0, :silence => false }.merge() exit_code = [:exit_code] silence = [:silence] $logger.debug { "options(#{.inspect})" } command = "#{command} 2>&1" $logger.debug { "command(#{command})" } output = %x( #{command} ) $logger.debug { "exit_code(#{$?})" } $logger.debug { "--------------------------------------------------------------------------------" } $logger.debug { output } $logger.debug { "--------------------------------------------------------------------------------" } @stdout.puts(output) if !silence raise CommandError, "run(#{command}) failed! [#{$?}]" if ($? != exit_code) output end |