Class: Shell::Options

Inherits:
Object
  • Object
show all
Includes:
ChefConfig::Mixin::DotD, ChefLicensing::CLIFlags::MixlibCLI, Mixlib::CLI
Defined in:
lib/chef/shell.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



225
226
227
228
# File 'lib/chef/shell.rb', line 225

def self.footer(text = nil)
  @footer = text if text
  @footer
end


350
351
352
353
354
355
356
357
358
359
# File 'lib/chef/shell.rb', line 350

def self.print_help
  instance = new
  instance.parse_options([])
  puts instance.opt_parser
  puts
  puts footer
  puts Chef::Licensing.licensing_help if ChefUtils::Dist::Infra::SHELL == "chef-shell"
  puts
  exit 1
end

.setup!Object



361
362
363
# File 'lib/chef/shell.rb', line 361

def self.setup!
  new.parse_opts
end

Instance Method Details

#parse_optsObject



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/chef/shell.rb', line 365

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