From 422dea05e755f0026c7786b46a7e93624da1ac0a Mon Sep 17 00:00:00 2001 From: Andrew Shafer Date: Mon, 16 Jun 2008 02:05:38 -0600 Subject: issue 1183 Added environment awareness to --configprint Pulled the logic for --configprint --genconfig and --genmanifest out of puppet.rb Put the logic in lib/puppet/util/settings.rb and refactored it a bit Added specs for the behavior Reformated the whole spec file to use nested describe Added the new method to the executables The old behavior should be preserved, except for the env is now used --- lib/puppet/util/settings.rb | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'lib/puppet/util/settings.rb') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 0e6f91e48..d8197f743 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -217,6 +217,64 @@ class Puppet::Util::Settings @used = [] end + # NOTE: ACS ahh the util classes. . .sigh + # as part of a fix for 1183, I pulled the logic for the following 5 methods out of the executables and puppet.rb + # They probably deserve their own class, but I don't want to do that until I can refactor environments + # its a little better than where they were + + # Prints the contents of a config file with the available config elements, or it + # prints a single value of a config element. + def print_config_options + env = value(:environment) + val = value(:configprint) + if val == "all" + hash = {} + each do |name, obj| + val = value(name,env) + val = val.inspect if val == "" + hash[name] = val + end + hash.sort { |a,b| a[0].to_s <=> b[0].to_s }.each do |name, val| + puts "%s = %s" % [name, val] + end + else + val.split(/\s*,\s*/).sort.each do |v| + if include?(v) + #if there is only one value, just print it for back compatibility + if v == val + puts value(val,env) + break + end + puts "%s = %s" % [v, value(v,env)] + else + puts "invalid parameter: %s" % v + return false + end + end + end + true + end + + def generate_config + puts to_config + true + end + + def generate_manifest + puts to_manifest + true + end + + def print_configs + return print_config_options if value(:configprint) != "" + return generate_config if value(:genconfig) + return generate_manifest if value(:genmanifest) + end + + def print_configs? + return (value(:configprint) != "" || value(:genconfig) || value(:genmanifest)) && true + end + # Return a given object's file metadata. def metadata(param) if obj = @config[symbolize(param)] and obj.is_a?(CFile) -- cgit