summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/settings/boolean_setting.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-08-19 11:31:19 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-08-24 11:36:20 +1000
commit058514aaf44f981a3239b402f2ff116ebf0d951f (patch)
tree12ee14aa7e1f693671167c2190ad1021e10d4fee /lib/puppet/util/settings/boolean_setting.rb
parentb0f219ad177c8e9c261578586f0324cef0c71cd2 (diff)
downloadpuppet-058514aaf44f981a3239b402f2ff116ebf0d951f.tar.gz
puppet-058514aaf44f981a3239b402f2ff116ebf0d951f.tar.xz
puppet-058514aaf44f981a3239b402f2ff116ebf0d951f.zip
Moving Setting classes into separate files
This isn't really a refactor, just moving code around. I did some simple method renaming, also. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/util/settings/boolean_setting.rb')
-rw-r--r--lib/puppet/util/settings/boolean_setting.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/puppet/util/settings/boolean_setting.rb b/lib/puppet/util/settings/boolean_setting.rb
new file mode 100644
index 000000000..cc2704c4e
--- /dev/null
+++ b/lib/puppet/util/settings/boolean_setting.rb
@@ -0,0 +1,33 @@
+require 'puppet/util/settings/setting'
+
+# A simple boolean.
+class Puppet::Util::Settings::BooleanSetting < Puppet::Util::Settings::Setting
+ # get the arguments in getopt format
+ def getopt_args
+ if short
+ [["--#{name}", "-#{short}", GetoptLong::NO_ARGUMENT],
+ ["--no-#{name}", GetoptLong::NO_ARGUMENT]]
+ else
+ [["--#{name}", GetoptLong::NO_ARGUMENT],
+ ["--no-#{name}", GetoptLong::NO_ARGUMENT]]
+ end
+ end
+
+ def optparse_args
+ if short
+ ["--[no-]#{name}", "-#{short}", desc, :NONE ]
+ else
+ ["--[no-]#{name}", desc, :NONE]
+ end
+ end
+
+ def munge(value)
+ case value
+ when true, "true"; return true
+ when false, "false"; return false
+ else
+ raise ArgumentError, "Invalid value '%s' for %s" %
+ [value.inspect, @name]
+ end
+ end
+end