summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/config.rb21
-rwxr-xr-xtest/other/config.rb31
2 files changed, 45 insertions, 7 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 680c9f2fb..0569424e3 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -143,12 +143,7 @@ class Config
# Handle a command-line argument.
def handlearg(opt, value = nil)
- if value == "true"
- value = true
- end
- if value == "false"
- value = false
- end
+ value = mungearg(value)
str = opt.sub(/^--/,'')
bool = true
newstr = str.sub(/^no-/, '')
@@ -196,6 +191,18 @@ class Config
end
end
+ # Convert arguments appropriately.
+ def mungearg(value)
+ # Handle different data types correctly
+ return case value
+ when /^false$/i: false
+ when /^true$/i: true
+ when /^\d+$/i: Integer(value)
+ else
+ value
+ end
+ end
+
# Return all of the parameters associated with a given section.
def params(section)
section = section.intern if section.is_a? String
@@ -236,7 +243,7 @@ class Config
when /^\s*$/: next # Skip blanks
when /^\s*(\w+)\s*=\s*(.+)$/: # settings
var = $1.intern
- value = $2
+ value = mungearg($2)
# Mmm, "special" attributes
if metas.include?(var.to_s)
diff --git a/test/other/config.rb b/test/other/config.rb
index b89dbe82b..95eab3b4d 100755
--- a/test/other/config.rb
+++ b/test/other/config.rb
@@ -594,6 +594,37 @@ yay = /a/path
end
end
end
+
+ def test_booleans_and_integers
+ config = mkconfig
+ config.setdefaults(:mysection,
+ :booltest => [false, "yay"],
+ :inttest => [14, "yay"]
+ )
+
+ file = tempfile()
+
+ File.open(file, "w") do |f|
+ f.puts %{
+[mysection]
+booltest = true
+inttest = 27
+}
+ end
+
+ assert_nothing_raised {
+ config.parse(file)
+ }
+
+ assert_equal(true, config[:booltest], "Boolean was not converted")
+ assert_equal(27, config[:inttest], "Integer was not converted")
+
+ # Now make sure that they get converted through handlearg
+ config.handlearg("--inttest", "true")
+ assert_equal(true, config[:inttest], "Boolean was not converted")
+ config.handlearg("--no-booltest", "false")
+ assert_equal(false, config[:booltest], "Boolean was not converted")
+ end
end
# $Id$