Module: Chef::Knife::DSL

Included in:
Rake::DSL
Defined in:
lib/knife/dsl/version.rb,
lib/knife/dsl.rb

Defined Under Namespace

Modules: Support

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#knife(command, args = []) ⇒ Object



26
27
28
# File 'lib/knife/dsl.rb', line 26

def knife(command, args=[])
  Chef::Knife::DSL::Support.run_knife(command, args)
end

#knife_capture(command, args = [], input = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/knife/dsl.rb', line 30

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

  status = Chef::Knife::DSL::Support.run_knife(command, args)
  return STDOUT.string, STDERR.string, status
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