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 135 def run 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 173 def no_command_given? ARGV.empty? end
no_subcommand_given?()
click to toggle source
# File lib/chef/application/knife.rb, line 169 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 185 def print_help_and_exit(exitcode=1, fatal_message=nil) Chef::Log.error(fatal_message) if fatal_message begin self.parse_options rescue OptionParser::InvalidOption => e puts "#{e}\n" end puts self.opt_parser puts Chef::Knife.list_commands exit exitcode end
quiet_traps()
click to toggle source
# File lib/chef/application/knife.rb, line 145 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 155 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 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 177 def want_help? ARGV[0] =~ /^(--help|-h)$/ end
want_version?()
click to toggle source
# File lib/chef/application/knife.rb, line 181 def want_version? ARGV[0] =~ /^(--version|-v)$/ end