Class: Chef::Knife::EnvironmentFromFile

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/environment_from_file.rb

Constant Summary

Constants inherited from Chef::Knife

CHEF_ORGANIZATION_MANAGEMENT, KNIFE_ROOT, OFFICIAL_PLUGINS, OPSCODE_HOSTED_CHEF_ACCESS_CONTROL, VERSION

Instance Attribute Summary

Attributes inherited from Chef::Knife

#name_args, #ui

Instance Method Summary collapse

Methods inherited from Chef::Knife

#api_key, #apply_computed_config, category, chef_config_dir, common_name, #config_file_defaults, #config_file_settings, config_loader, #config_source, #configure_chef, #create_object, #delete_object, dependency_loaders, deps, #format_rest_error, guess_category, #humanize_exception, #humanize_http_exception, inherited, #initialize, list_commands, load_commands, load_config, load_deps, #maybe_setup_fips, #merge_configs, msg, #noauth_rest, #parse_options, reset_config_loader!, reset_subcommands!, #rest, #root_rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_files, subcommand_loader, subcommands, subcommands_by_category, #test_mandatory_field, ui, unnamed?, use_separate_defaults?, #username

Constructor Details

This class inherits a constructor from Chef::Knife

Instance Method Details

#environments_pathObject



41
42
43
# File 'lib/chef/knife/environment_from_file.rb', line 41

def environments_path
  @environments_path ||= "environments"
end

#find_all_environmentsObject



45
46
47
# File 'lib/chef/knife/environment_from_file.rb', line 45

def find_all_environments
  loader.find_all_objects("./#{environments_path}/")
end

#load_all_environmentsObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/chef/knife/environment_from_file.rb', line 49

def load_all_environments
  environments = find_all_environments
  if environments.empty?
    ui.fatal("Unable to find any environment files in '#{environments_path}'")
    exit(1)
  end
  environments.each do |env|
    load_environment(env)
  end
end

#load_environment(env) ⇒ Object



60
61
62
63
64
65
# File 'lib/chef/knife/environment_from_file.rb', line 60

def load_environment(env)
  updated = loader.load_from("environments", env)
  updated.save
  output(format_for_display(updated)) if config[:print_after]
  ui.info("Updated Environment #{updated.name}")
end

#loaderObject



37
38
39
# File 'lib/chef/knife/environment_from_file.rb', line 37

def loader
  @loader ||= Knife::Core::ObjectLoader.new(Chef::Environment, ui)
end

#runObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/chef/knife/environment_from_file.rb', line 67

def run
  if config[:all] == true
    load_all_environments
  else
    if @name_args[0].nil?
      show_usage
      ui.fatal("You must specify a file to load")
      exit 1
    end

    @name_args.each do |arg|
      load_environment(arg)
    end
  end
end