diff options
Diffstat (limited to 'lib/chef/knife.rb')
-rw-r--r-- | lib/chef/knife.rb | 83 |
1 files changed, 46 insertions, 37 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index dde6fd74a6..c8b344b5f1 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -235,51 +235,60 @@ class Chef OFFICIAL_PLUGINS = %w{ec2 rackspace windows openstack terremark bluebox} - def self.path_from_caller(caller_line) - caller_line.split(/:\d+/).first - end - - # :nodoc: - # Error out and print usage. probably because the arguments given by the - # user could not be resolved to a subcommand. - def self.subcommand_not_found!(args) - ui.fatal("Cannot find subcommand for: '#{args.join(' ')}'") + class << self + private - # Mention rehash when the subcommands cache(plugin_manifest.json) is used - if subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::HashedCommandLoader) || - subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::CustomManifestLoader) - ui.info("If this is a recently installed plugin, please run 'knife rehash' to update the subcommands cache.") + # @api private + def path_from_caller(caller_line) + caller_line.split(/:\d+/).first end - if category_commands = guess_category(args) - list_commands(category_commands) - elsif missing_plugin = ( OFFICIAL_PLUGINS.find { |plugin| plugin == args[0] } ) - ui.info("The #{missing_plugin} commands were moved to plugins in Chef 0.10") - ui.info("You can install the plugin with `(sudo) gem install knife-#{missing_plugin}`") - ui.info("Use `chef gem install knife-#{missing_plugin}` instead if using ChefDK") - else - list_commands - end + # :nodoc: + # Error out and print usage. probably because the arguments given by the + # user could not be resolved to a subcommand. + # @api private + def subcommand_not_found!(args) + ui.fatal("Cannot find subcommand for: '#{args.join(' ')}'") + + # Mention rehash when the subcommands cache(plugin_manifest.json) is used + if subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::HashedCommandLoader) || + subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::CustomManifestLoader) + ui.info("If this is a recently installed plugin, please run 'knife rehash' to update the subcommands cache.") + end - exit 10 - end + if category_commands = guess_category(args) + list_commands(category_commands) + elsif missing_plugin = ( OFFICIAL_PLUGINS.find { |plugin| plugin == args[0] } ) + ui.info("The #{missing_plugin} commands were moved to plugins in Chef 0.10") + ui.info("You can install the plugin with `(sudo) gem install knife-#{missing_plugin}`") + ui.info("Use `chef gem install knife-#{missing_plugin}` instead if using ChefDK") + else + list_commands + end - def self.list_commands(preferred_category = nil) - category_desc = preferred_category ? preferred_category + " " : "" - msg "Available #{category_desc}subcommands: (for details, knife SUB-COMMAND --help)\n\n" - subcommand_loader.list_commands(preferred_category).sort.each do |category, commands| - next if category =~ /deprecated/i - msg "** #{category.upcase} COMMANDS **" - commands.sort.each do |command| - subcommand_loader.load_command(command) - msg subcommands[command].banner if subcommands[command] + exit 10 + end + + # @api private + def list_commands(preferred_category = nil) + category_desc = preferred_category ? preferred_category + " " : "" + msg "Available #{category_desc}subcommands: (for details, knife SUB-COMMAND --help)\n\n" + subcommand_loader.list_commands(preferred_category).sort.each do |category, commands| + next if category =~ /deprecated/i + msg "** #{category.upcase} COMMANDS **" + commands.sort.each do |command| + subcommand_loader.load_command(command) + msg subcommands[command].banner if subcommands[command] + end + msg end - msg end - end - def self.reset_config_path! - @@chef_config_dir = nil + # @api private + def reset_config_path! + @@chef_config_dir = nil + end + end reset_config_path! |