class Chef::Application::Knife
Constants
- NO_COMMAND_GIVEN
Public Instance Methods
run()
click to toggle source
Run knife
# File lib/chef/application/knife.rb, line 160 def run ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME" Mixlib::Log::Formatter.show_time = false validate_and_parse_options quiet_traps Chef::Knife.run(ARGV, options) exit 0 end
Private Instance Methods
no_command_given?()
click to toggle source
# File lib/chef/application/knife.rb, line 199 def no_command_given? ARGV.empty? end
no_subcommand_given?()
click to toggle source
# File lib/chef/application/knife.rb, line 195 def no_subcommand_given? ARGV[0] =~ /^-/ end
print_help_and_exit(exitcode = 1, fatal_message = nil)
click to toggle source
# File lib/chef/application/knife.rb, line 211 def print_help_and_exit(exitcode = 1, fatal_message = nil) Chef::Log.error(fatal_message) if fatal_message begin parse_options rescue OptionParser::InvalidOption => e puts "#{e}\n" end if want_help? puts "#{ChefUtils::Dist::Infra::PRODUCT}: #{Chef::VERSION}" puts puts "Docs: #{ChefUtils::Dist::Org::KNIFE_DOCS}" puts "Patents: #{ChefUtils::Dist::Org::PATENTS}" puts end puts opt_parser puts Chef::Knife.list_commands exit exitcode end
quiet_traps()
click to toggle source
# File lib/chef/application/knife.rb, line 171 def quiet_traps trap("TERM") do exit 1 end trap("INT") do exit 2 end end
validate_and_parse_options()
click to toggle source
# File lib/chef/application/knife.rb, line 181 def validate_and_parse_options # Checking ARGV validity *before* parse_options because parse_options # mangles ARGV in some situations if no_command_given? print_help_and_exit(1, NO_COMMAND_GIVEN) elsif no_subcommand_given? if want_help? || want_version? print_help_and_exit(0) else print_help_and_exit(2, NO_COMMAND_GIVEN) end end end
want_help?()
click to toggle source
# File lib/chef/application/knife.rb, line 203 def want_help? ARGV[0] =~ /^(--help|-h)$/ end
want_version?()
click to toggle source
# File lib/chef/application/knife.rb, line 207 def want_version? ARGV[0] =~ /^(--version|-v)$/ end