class Shell::Options

Public Class Methods

print_help() click to toggle source
setup!() click to toggle source
# File lib/chef/shell.rb, line 278
def self.setup!
  self.new.parse_opts
end

Public Instance Methods

parse_opts() click to toggle source
# File lib/chef/shell.rb, line 282
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
  config[:config_file] = config_file_for_shell_mode(environment)
  config_msg = config[:config_file] || "none (standalone session)"
  puts "loading configuration: #{config_msg}"
  Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exists?(config[:config_file]) && File.readable?(config[:config_file])
  Chef::Config.merge!(config)
end

Private Instance Methods

config_file_for_shell_mode(environment) click to toggle source
# File lib/chef/shell.rb, line 297
def config_file_for_shell_mode(environment)
  if config[:config_file]
    config[:config_file]
  elsif environment && ENV['HOME']
    Shell.env = environment
    config_file_to_try = ::File.join(ENV['HOME'], '.chef', environment, 'chef_shell.rb')
    unless ::File.exist?(config_file_to_try)
      puts "could not find chef-shell config for environment #{environment} at #{config_file_to_try}"
      exit 1
    end
    config_file_to_try
  elsif ENV['HOME'] && ::File.exist?(File.join(ENV['HOME'], '.chef', 'chef_shell.rb'))
    File.join(ENV['HOME'], '.chef', 'chef_shell.rb')
  elsif config[:solo]
    "/etc/chef/solo.rb"
  elsif config[:client]
    "/etc/chef/client.rb"
  else
    nil
  end
end