Skip to content

Commit

Permalink
added exit codes to the return values.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh committed Nov 9, 2012
1 parent 9c94b4d commit 4386abe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ require 'pp'
require 'json'

task :list_nodes do
knife :node_list
status = knife :node_list
fail if status > 0
end

task :show_node, :node_name do |task_name, args|
stdout, stderr = knife_capture :node_show, [args[:node_name], '-F', 'j']
stdout, stderr, status = knife_capture :node_show, [args[:node_name], '-F', 'j']
fail if status > 0
pp JSON.load(stdout)
end
```
Expand Down
7 changes: 5 additions & 2 deletions lib/knife/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def self.run_knife(command, args)

opts = Chef::Application::Knife.new.options
Chef::Knife.run(command, opts)
return 0
rescue SystemExit => e
return e.status
end
end

Expand All @@ -36,8 +39,8 @@ def knife_capture(command, args=[], input=nil)
Object.const_set("STDIN", input ? StringIO.new(input, 'r') : null)
$VERBOSE = warn

Chef::Knife::DSL::Support.run_knife(command, args)
return STDOUT.string, STDERR.string
status = Chef::Knife::DSL::Support.run_knife(command, args)
return STDOUT.string, STDERR.string, status
ensure
warn = $VERBOSE
$VERBOSE = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/knife/dsl/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Chef
class Knife
module DSL
VERSION = "0.0.1"
VERSION = "0.0.2"
end
end
end

0 comments on commit 4386abe

Please sign in to comment.