diff options
author | Andrew Shafer <andrew@reductivelabs.com> | 2008-06-16 02:05:38 -0600 |
---|---|---|
committer | Andrew Shafer <andrew@reductivelabs.com> | 2008-06-16 02:07:24 -0600 |
commit | 422dea05e755f0026c7786b46a7e93624da1ac0a (patch) | |
tree | 0eeae0da5329071f5bad1059a2d32b8ad4a8a242 /lib | |
parent | 5273b22b4fda6f9aa7a8366a1dfbae092594d391 (diff) | |
download | puppet-422dea05e755f0026c7786b46a7e93624da1ac0a.tar.gz puppet-422dea05e755f0026c7786b46a7e93624da1ac0a.tar.xz puppet-422dea05e755f0026c7786b46a7e93624da1ac0a.zip |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet.rb | 43 | ||||
-rw-r--r-- | lib/puppet/util/settings.rb | 58 |
2 files changed, 58 insertions, 43 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 66a52f9e3..83e5da68f 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -117,49 +117,6 @@ module Puppet # Load all of the configuration parameters. require 'puppet/defaults' - # Prints the contents of a config file with the available config elements, or it - # prints a single value of a config element. - def self.genconfig - if Puppet[:configprint] != "" - val = Puppet[:configprint] - if val == "all" - hash = {} - Puppet.settings.each do |name, obj| - val = obj.value - case val - when true, false, "": val = val.inspect - end - 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 - elsif val =~ /,/ - val.split(/\s*,\s*/).sort.each do |v| - if Puppet.settings.include?(v) - puts "%s = %s" % [v, Puppet[v]] - else - puts "invalid parameter: %s" % v - exit(1) - end - end - else - val.split(/\s*,\s*/).sort.each do |v| - if Puppet.settings.include?(v) - puts Puppet[val] - else - puts "invalid parameter: %s" % v - exit(1) - end - end - end - exit(0) - end - if Puppet[:genconfig] - puts Puppet.settings.to_config - exit(0) - end - end def self.genmanifest if Puppet[:genmanifest] 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) |