~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to lib/puppet/settings/boolean_setting.rb

  • Committer: Benjamin Kerensa
  • Date: 2012-11-21 23:50:52 UTC
  • mfrom: (1.1.30)
  • Revision ID: bkerensa@ubuntu.com-20121121235052-ah7nzabp77sh69gb
New Upstream Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppet/settings/base_setting'
 
2
 
 
3
# A simple boolean.
 
4
class Puppet::Settings::BooleanSetting < Puppet::Settings::BaseSetting
 
5
  # get the arguments in getopt format
 
6
  def getopt_args
 
7
    if short
 
8
      [["--#{name}", "-#{short}", GetoptLong::NO_ARGUMENT], ["--no-#{name}", GetoptLong::NO_ARGUMENT]]
 
9
    else
 
10
      [["--#{name}", GetoptLong::NO_ARGUMENT], ["--no-#{name}", GetoptLong::NO_ARGUMENT]]
 
11
    end
 
12
  end
 
13
 
 
14
  def optparse_args
 
15
    if short
 
16
      ["--[no-]#{name}", "-#{short}", desc, :NONE ]
 
17
    else
 
18
      ["--[no-]#{name}", desc, :NONE]
 
19
    end
 
20
  end
 
21
 
 
22
  def munge(value)
 
23
    case value
 
24
    when true, "true"; return true
 
25
    when false, "false"; return false
 
26
    else
 
27
      raise Puppet::Settings::ValidationError, "Invalid value '#{value.inspect}' for boolean parameter: #{@name}"
 
28
    end
 
29
  end
 
30
 
 
31
  def type
 
32
    :boolean
 
33
  end
 
34
end