class Chef::Knife::ConfigUseProfile

Public Instance Methods

configure_chef() click to toggle source

Disable normal config loading since this shouldn't fail if the profile doesn't exist of the config is otherwise corrupted.

# File lib/chef/knife/config_use_profile.rb, line 29
def configure_chef
  apply_computed_config
end
run() click to toggle source
# File lib/chef/knife/config_use_profile.rb, line 33
def run
  context_file = ChefConfig::PathHelper.home(".chef", "context").freeze
  profile = @name_args[0]&.strip
  if profile && !profile.empty?
    # Ensure the .chef/ folder exists.
    FileUtils.mkdir_p(File.dirname(context_file))
    IO.write(context_file, "#{profile}\n")
    ui.msg("Set default profile to #{profile}")
  else
    show_usage
    ui.fatal("You must specify a profile")
    exit 1
  end
end