class Puppet::Interface::OptionBuilder

@api public

Attributes

option[R]

The option under construction @return [Puppet::Interface::Option] @api private

Public Class Methods

build(face, *declaration, &block) click to toggle source

Build an option @return [Puppet::Interface::Option] @api private

   # File lib/puppet/interface/option_builder.rb
11 def self.build(face, *declaration, &block)
12   new(face, *declaration, &block).option
13 end
new(face, *declaration, &block) click to toggle source
   # File lib/puppet/interface/option_builder.rb
15 def initialize(face, *declaration, &block)
16   @face   = face
17   @option = Puppet::Interface::Option.new(face, *declaration)
18   instance_eval(&block) if block_given?
19   @option
20 end

Public Instance Methods

after_action(&block) click to toggle source

Sets a block to be executed after an action is invoked. !(see before_action) @api public @dsl Faces

   # File lib/puppet/interface/option_builder.rb
62 def after_action(&block)
63   unless block
64     #TRANSLATORS 'after_action' is a method name and should not be translated
65     raise ArgumentError, _("%{option} after_action requires a block") % { option: @option }
66   end
67   if @option.after_action
68     #TRANSLATORS 'after_action' is a method name and should not be translated
69     raise ArgumentError, _("%{option} already has an after_action set") % { option: @option }
70   end
71   unless block.arity == 3 then
72     #TRANSLATORS 'after_action' is a method name and should not be translated
73     raise ArgumentError, _("after_action takes three arguments, action, args, and options")
74   end
75   @option.after_action = block
76 end
before_action(&block) click to toggle source

Sets a block to be executed when an action is invoked before the main action code. This is most commonly used to validate an option. @yieldparam action [Puppet::Interface::Action] The action being

invoked

@yieldparam args [Array] The arguments given to the action @yieldparam options [Hash<Symbol=>Object>] Any options set @api public @dsl Faces

   # File lib/puppet/interface/option_builder.rb
42 def before_action(&block)
43   unless block
44     #TRANSLATORS 'before_action' is a method name and should not be translated
45     raise ArgumentError, _("%{option} before_action requires a block") % { option: @option }
46   end
47   if @option.before_action
48     #TRANSLATORS 'before_action' is a method name and should not be translated
49     raise ArgumentError, _("%{option} already has a before_action set") % { option: @option }
50   end
51   unless block.arity == 3 then
52     #TRANSLATORS 'before_action' is a method name and should not be translated
53     raise ArgumentError, _("before_action takes three arguments, action, args, and options")
54   end
55   @option.before_action = block
56 end
default_to(&block) click to toggle source

Sets a block that will be used to compute the default value for this option. It will be evaluated when the action is invoked. The block should take no arguments. @api public @dsl Faces

    # File lib/puppet/interface/option_builder.rb
 91 def default_to(&block)
 92   unless block
 93     #TRANSLATORS 'default_to' is a method name and should not be translated
 94     raise ArgumentError, _("%{option} default_to requires a block") % { option: @option }
 95   end
 96   if @option.has_default?
 97     raise ArgumentError, _("%{option} already has a default value") % { option: @option }
 98   end
 99   unless block.arity == 0
100     #TRANSLATORS 'default_to' is a method name and should not be translated
101     raise ArgumentError, _("%{option} default_to block should not take any arguments") % { option: @option }
102   end
103   @option.default = block
104 end
required(value = true) click to toggle source

Sets whether the option is required. If no argument is given it defaults to setting it as a required option. @api public @dsl Faces

   # File lib/puppet/interface/option_builder.rb
82 def required(value = true)
83   @option.required = value
84 end