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 157
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 196
def no_command_given?
  ARGV.empty?
end
no_subcommand_given?() click to toggle source
# File lib/chef/application/knife.rb, line 192
def no_subcommand_given?
  ARGV[0] =~ /^-/
end
print_help_and_exit(exitcode = 1, fatal_message = nil) click to toggle source
quiet_traps() click to toggle source
# File lib/chef/application/knife.rb, line 168
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 178
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 200
def want_help?
  ARGV[0] =~ /^(--help|-h)$/
end
want_version?() click to toggle source
# File lib/chef/application/knife.rb, line 204
def want_version?
  ARGV[0] =~ /^(--version|-v)$/
end