Class: Spaux::Chef::Knife
- Inherits:
-
Chef::Application::Knife
- Object
- Chef::Application::Knife
- Spaux::Chef::Knife
- Defined in:
- lib/spaux/chef/knife.rb
Constant Summary collapse
- DEFAULT_KNIFE_CONFIG =
{ config_file: { flags: %w(--config -c), value: ::File.join('@work_dir', 'knife.rb') } }
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#work_dir ⇒ Object
Returns the value of attribute work_dir.
Instance Method Summary collapse
-
#initialize(work_dir, args) ⇒ Knife
constructor
A new instance of Knife.
- #run ⇒ Object
Constructor Details
#initialize(work_dir, args) ⇒ Knife
Returns a new instance of Knife.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spaux/chef/knife.rb', line 19 def initialize(work_dir, args) @work_dir = work_dir @args = args DEFAULT_KNIFE_CONFIG.each do |_,v| v[:value].is_a?(String) && v[:value].gsub!(/@work_dir/, @work_dir) end cf_flags = DEFAULT_KNIFE_CONFIG[:config_file][:flags] unless @args.include?(cf_flags.first) || @args.include?(cf_flags.last) @args << DEFAULT_KNIFE_CONFIG[:config_file][:flags].first @args << DEFAULT_KNIFE_CONFIG[:config_file][:value] end config_file = DEFAULT_KNIFE_CONFIG[:config_file][:value] FileUtils.touch config_file end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
17 18 19 |
# File 'lib/spaux/chef/knife.rb', line 17 def args @args end |
#work_dir ⇒ Object
Returns the value of attribute work_dir.
16 17 18 |
# File 'lib/spaux/chef/knife.rb', line 16 def work_dir @work_dir end |
Instance Method Details
#run ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spaux/chef/knife.rb', line 37 def run Mixlib::Log::Formatter.show_time = false quiet_traps # I'm not sure why I have to do this if this class is child # of Chef::Application::Knife, so options should be set already knife = ::Chef::Application::Knife.new = knife. begin ::Chef::Knife.run(@args, ) rescue SystemExit => e # just ignore the exit of knife tool end end |