Class: Shell::Options

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



231
232
233
234
# File 'lib/chef/shell.rb', line 231

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


340
341
342
343
344
345
346
347
348
# File 'lib/chef/shell.rb', line 340

def self.print_help
  instance = new
  instance.parse_options([])
  puts instance.opt_parser
  puts
  puts footer
  puts
  exit 1
end

.setup!Object



350
351
352
# File 'lib/chef/shell.rb', line 350

def self.setup!
  new.parse_opts
end

Instance Method Details

#parse_optsObject



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/chef/shell.rb', line 354

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