Module: ChefWorkflow::KnifePluginSupport

Included in:
VM::ChefServerProvisioner, VM::KnifeProvisioner
Defined in:
lib/chef-workflow/support/knife-plugin.rb

Overview

Mixin to add methods to assist with creating knife plugins.

Instance Method Summary collapse

Instance Method Details

#init_knife_plugin(klass, args) ⇒ Object

Given a class name for a plugin compatible with the Chef::Knife interface, initializes it and makes it available for execution. It also overrides the ‘ui` object to use `StringIO` objects, which allow you to choose when and if you display the output of the commands by referencing `obj.ui.stdout.string` and similar calls.

The second argument is an array of arguments to the command, such as they would be presented to a command line tool as ‘ARGV`.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chef-workflow/support/knife-plugin.rb', line 21

def init_knife_plugin(klass, args)
  klass.options = Chef::Application::Knife.options.merge(klass.options)
  klass.load_deps
  cli = klass.new(args)
  cli.ui = Chef::Knife::UI.new(
    StringIO.new('', 'w'),
    StringIO.new('', 'w'),
    StringIO.new('', 'r'),
    cli.config
  )

  return cli
end