Class: Chef::Knife::EnvironmentFromFile

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

Instance Method Summary collapse

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