Parent

Files

Class/Module Index [+]

Quicksearch

Chef::Knife::SubcommandLoader

Attributes

chef_config_dir[R]
env[R]

Public Class Methods

new(chef_config_dir, env=ENV) click to toggle source
# File lib/chef/knife/core/subcommand_loader.rb, line 30
def initialize(chef_config_dir, env=ENV)
  @chef_config_dir, @env = chef_config_dir, env
  @forced_activate = {}
end

Public Instance Methods

find_subcommands_via_dirglob() click to toggle source
# File lib/chef/knife/core/subcommand_loader.rb, line 77
def find_subcommands_via_dirglob
  # The "require paths" of the core knife subcommands bundled with chef
  files = Dir[File.expand_path('../../../knife/*.rb', __FILE__)]
  subcommand_files = {}
  files.each do |knife_file|
    rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/,1]
    subcommand_files[rel_path] = knife_file
  end
  subcommand_files
end
find_subcommands_via_rubygems() click to toggle source
# File lib/chef/knife/core/subcommand_loader.rb, line 88
def find_subcommands_via_rubygems
  files = Gem.find_files 'chef/knife/*.rb'
  files.reject! {|f| from_old_gem?(f) }
  subcommand_files = {}
  files.each do |file|
    rel_path = file[/(#{Regexp.escape File.join('chef', 'knife', '')}.*)\.rb/, 1]
    subcommand_files[rel_path] = file
  end

  subcommand_files.merge(find_subcommands_via_dirglob)
end
gem_and_builtin_subcommands() click to toggle source

Returns a Hash of paths to knife commands built-in to chef, or installed via gem. If rubygems is not installed, falls back to globbing the knife directory. The Hash is of the form {"relative/path" => "/absolute/path"}

# File lib/chef/knife/core/subcommand_loader.rb, line 65
def gem_and_builtin_subcommands
  # search all gems for chef/knife/*.rb
  require 'rubygems'
  find_subcommands_via_rubygems
rescue LoadError
  find_subcommands_via_dirglob
end
load_commands() click to toggle source

Load all the sub-commands

# File lib/chef/knife/core/subcommand_loader.rb, line 36
def load_commands
  subcommand_files.each { |subcommand| Kernel.load subcommand }
  true
end
site_subcommands() click to toggle source

Returns an Array of paths to knife commands located in chef_config_dir/plugins/knife/ and ~/.chef/plugins/knife/

# File lib/chef/knife/core/subcommand_loader.rb, line 43
def site_subcommands
  user_specific_files = []

  if chef_config_dir
    user_specific_files.concat Dir.glob(File.expand_path("plugins/knife/*.rb", chef_config_dir))
  end

  # finally search ~/.chef/plugins/knife/*.rb
  user_specific_files.concat Dir.glob(File.join(env['HOME'], '.chef', 'plugins', 'knife', '*.rb')) if env['HOME']

  user_specific_files
end
subcommand_files() click to toggle source
# File lib/chef/knife/core/subcommand_loader.rb, line 73
def subcommand_files
  @subcommand_files ||= (gem_and_builtin_subcommands.values + site_subcommands).flatten.uniq
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.