forked from danryan/knife-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dba1164
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'knife/dsl' | ||
|
||
task :list_nodes do | ||
knife :node_list | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'chef/application/knife' | ||
require 'stringio' | ||
|
||
module Chef::Knife::DSL | ||
module Chef::Knife::DSL::Support | ||
def self.run_knife(command, args) | ||
unless command.kind_of?(Array) | ||
command = command.to_s.split(/[\s_]+/) | ||
end | ||
|
||
command += args | ||
|
||
if ENV["CHEF_CONFIG"] | ||
command += ['-c', ENV["CHEF_CONFIG"]] | ||
end | ||
|
||
opts = Chef::Application::Knife.new.options | ||
Chef::Knife.run(command, opts) | ||
end | ||
end | ||
|
||
def knife(command, args=[]) | ||
Chef::Knife::DSL::Support.run_knife(command, args) | ||
end | ||
|
||
def knife_capture(command, args=[], input=nil) | ||
null = Gem.win_platform? ? File.open('NUL:', 'r') : File.open('/dev/null', 'r') | ||
|
||
warn = $VERBOSE | ||
$VERBOSE = nil | ||
stderr, stdout, stdin = STDERR, STDOUT, STDIN | ||
|
||
Object.const_set("STDERR", StringIO.new('', 'r+')) | ||
Object.const_set("STDOUT", StringIO.new('', 'r+')) | ||
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 | ||
ensure | ||
warn = $VERBOSE | ||
$VERBOSE = nil | ||
Object.const_set("STDERR", stderr) | ||
Object.const_set("STDOUT", stdout) | ||
Object.const_set("STDIN", stdin) | ||
$VERBOSE = warn | ||
null.close | ||
end | ||
end | ||
|
||
class << eval("self", TOPLEVEL_BINDING) | ||
include Chef::Knife::DSL | ||
end | ||
|
||
if defined? Rake::DSL | ||
module Rake::DSL | ||
include Chef::Knife::DSL | ||
end | ||
end |