diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-08 20:54:49 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-08 20:54:49 +0000 |
commit | 1fc4ec373f8ee272077e2e78a380ac78879ffabe (patch) | |
tree | fbae3b75f9240c607f98c05485c55506c94d0c4a | |
parent | c90d0b1144c095ecd16f3e3243b003adc686675c (diff) | |
download | puppet-1fc4ec373f8ee272077e2e78a380ac78879ffabe.tar.gz puppet-1fc4ec373f8ee272077e2e78a380ac78879ffabe.tar.xz puppet-1fc4ec373f8ee272077e2e78a380ac78879ffabe.zip |
Fixing #167. Started with the submitted patch and made a few more modifications, and added a regression test.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1247 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/config.rb | 21 | ||||
-rwxr-xr-x | test/other/config.rb | 31 |
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$ |