class Shell::Options
Public Class Methods
Source
# File lib/chef/shell.rb, line 326 def self.print_help instance = new instance.parse_options([]) puts instance.opt_parser puts puts footer puts exit 1 end
Public Instance Methods
Source
# File lib/chef/shell.rb, line 340 def parse_opts remainder = parse_options environment = remainder.first # We have to nuke ARGV to make sure irb's option parser never sees it. # otherwise, IRB complains about command line switches it doesn't recognize. ARGV.clear # This code should not exist. # We should be using Application::Client and then calling load_config_file # which does all this properly. However this will do for now. config[:config_file] = config_file_for_shell_mode(environment) config_msg = config[:config_file] || "none (standalone session)" puts "loading configuration: #{config_msg}" # load the config (if we have one) unless config[:config_file].nil? if File.exist?(config[:config_file]) && File.readable?(config[:config_file]) Chef::Config.from_file(config[:config_file]) end # even if we couldn't load that, we need to tell Chef::Config what # the file was so it sets conf dir and d_dir and such properly Chef::Config[:config_file] = config[:config_file] # now attempt to load any relevant dot-dirs load_dot_d(Chef::Config[:client_d_dir]) if Chef::Config[:client_d_dir] end # finally merge command-line options in Chef::Config.merge!(config) end
Private Instance Methods
Source
# File lib/chef/shell.rb, line 375 def apply_config(config_content, config_file_path) Chef::Config.from_string(config_content, config_file_path) rescue Exception => error logger.fatal("Configuration error #{error.class}: #{error.message}") filtered_trace = error.backtrace.grep(/#{Regexp.escape(config_file_path)}/) filtered_trace.each { |line| logger.fatal(" " + line ) } raise Chef::Exceptions::ConfigurationError.new("Aborting due to error in '#{config_file_path}': #{error}") end
shamelessly lifted from application.rb
Source
# File lib/chef/shell.rb, line 384 def config_file_for_shell_mode(environment) dot_chef_dir = Chef::Util::PathHelper.home(".chef") if config[:config_file] config[:config_file] elsif environment Shell.env = environment config_file_to_try = ::File.join(dot_chef_dir, environment, ChefUtils::Dist::Infra::SHELL_CONF) unless ::File.exist?(config_file_to_try) puts "could not find #{ChefUtils::Dist::Infra::SHELL} config for environment #{environment} at #{config_file_to_try}" exit 1 end config_file_to_try elsif dot_chef_dir && ::File.exist?(File.join(dot_chef_dir, ChefUtils::Dist::Infra::SHELL_CONF)) File.join(dot_chef_dir, ChefUtils::Dist::Infra::SHELL_CONF) elsif config[:solo_legacy_shell] Chef::Config.platform_specific_path("#{ChefConfig::Config.etc_chef_dir}/solo.rb") elsif config[:client] Chef::Config.platform_specific_path("#{ChefConfig::Config.etc_chef_dir}/client.rb") elsif config[:solo_shell] Chef::WorkstationConfigLoader.new(nil, Chef::Log).config_location else nil end end