summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-06 18:56:27 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:35 +1000
commitbe30a618272d9828f90f5e726a23021be3b23221 (patch)
tree591c714beb292cc81c278ef481d2262daede2629 /lib/puppet
parent863c50b1273a7fa48d74fb74948938214b45967c (diff)
downloadpuppet-be30a618272d9828f90f5e726a23021be3b23221.tar.gz
puppet-be30a618272d9828f90f5e726a23021be3b23221.tar.xz
puppet-be30a618272d9828f90f5e726a23021be3b23221.zip
Adding a common Settings method for setting values
We were previously missing some hooks for settings set via the command-line, because different code paths were being used. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/util/settings.rb68
1 files changed, 34 insertions, 34 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index c60f1713b..f9b9345f3 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -22,29 +22,7 @@ class Puppet::Util::Settings
# Set a config value. This doesn't set the defaults, it sets the value itself.
def []=(param, value)
- param = param.to_sym
- unless element = @config[param]
- raise ArgumentError,
- "Attempt to assign a value to unknown configuration parameter %s" % param.inspect
- end
- if element.respond_to?(:munge)
- value = element.munge(value)
- end
- if element.respond_to?(:handle)
- element.handle(value)
- end
- # Reset the name, so it's looked up again.
- if param == :name
- @name = nil
- end
- @sync.synchronize do # yay, thread-safe
- @values[:memory][param] = value
- @cache.clear
-
- clearused
- end
-
- return value
+ set_value(param, value, :memory)
end
# Generate the list of valid arguments, in a format that GetoptLong can
@@ -156,7 +134,7 @@ class Puppet::Util::Settings
end
# Handle a command-line argument.
- def handlearg(opt, value = nil)
+ def handlearg(opt, value)
@cache.clear
value = munge_value(value) if value
str = opt.sub(/^--/,'')
@@ -167,17 +145,12 @@ class Puppet::Util::Settings
bool = false
end
str = str.intern
- if self.valid?(str)
- @sync.synchronize do
- if self.boolean?(str)
- @values[:cli][str] = bool
- else
- @values[:cli][str] = value
- end
- end
- else
- raise ArgumentError, "Invalid argument %s" % opt
+
+ if value == ""
+ value = bool
end
+
+ set_value(str, value, :cli)
end
def include?(name)
@@ -488,6 +461,33 @@ class Puppet::Util::Settings
return sectionlist, sections
end
+ def set_value(param, value, type)
+ param = param.to_sym
+ unless element = @config[param]
+ raise ArgumentError,
+ "Attempt to assign a value to unknown configuration parameter %s" % param.inspect
+ end
+ if element.respond_to?(:munge)
+ value = element.munge(value)
+ end
+ if element.respond_to?(:handle)
+ element.handle(value)
+ end
+ # Reset the name, so it's looked up again.
+ if param == :name
+ @name = nil
+ end
+ @sync.synchronize do # yay, thread-safe
+ @values[type][param] = value
+ @cache.clear
+ clearused
+ end
+
+ return value
+ end
+
+ private :set_value
+
# Set a bunch of defaults in a given section. The sections are actually pretty
# pointless, but they help break things up a bit, anyway.
def setdefaults(section, defs)