class Puppet::Interface::OptionBuilder
@api public
Attributes
The option under construction @return [Puppet::Interface::Option] @api private
Public Class Methods
Build an option @return [Puppet::Interface::Option] @api private
# File lib/puppet/interface/option_builder.rb 12 def self.build(face, *declaration, &block) 13 new(face, *declaration, &block).option 14 end
# File lib/puppet/interface/option_builder.rb 16 def initialize(face, *declaration, &block) 17 @face = face 18 @option = Puppet::Interface::Option.new(face, *declaration) 19 instance_eval(&block) if block_given? 20 @option 21 end
Public Instance Methods
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 63 def after_action(&block) 64 unless block 65 #TRANSLATORS 'after_action' is a method name and should not be translated 66 raise ArgumentError, _("%{option} after_action requires a block") % { option: @option } 67 end 68 if @option.after_action 69 #TRANSLATORS 'after_action' is a method name and should not be translated 70 raise ArgumentError, _("%{option} already has an after_action set") % { option: @option } 71 end 72 unless block.arity == 3 then 73 #TRANSLATORS 'after_action' is a method name and should not be translated 74 raise ArgumentError, _("after_action takes three arguments, action, args, and options") 75 end 76 @option.after_action = block 77 end
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 43 def before_action(&block) 44 unless block 45 #TRANSLATORS 'before_action' is a method name and should not be translated 46 raise ArgumentError, _("%{option} before_action requires a block") % { option: @option } 47 end 48 if @option.before_action 49 #TRANSLATORS 'before_action' is a method name and should not be translated 50 raise ArgumentError, _("%{option} already has a before_action set") % { option: @option } 51 end 52 unless block.arity == 3 then 53 #TRANSLATORS 'before_action' is a method name and should not be translated 54 raise ArgumentError, _("before_action takes three arguments, action, args, and options") 55 end 56 @option.before_action = block 57 end
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 92 def default_to(&block) 93 unless block 94 #TRANSLATORS 'default_to' is a method name and should not be translated 95 raise ArgumentError, _("%{option} default_to requires a block") % { option: @option } 96 end 97 if @option.has_default? 98 raise ArgumentError, _("%{option} already has a default value") % { option: @option } 99 end 100 unless block.arity == 0 101 #TRANSLATORS 'default_to' is a method name and should not be translated 102 raise ArgumentError, _("%{option} default_to block should not take any arguments") % { option: @option } 103 end 104 @option.default = block 105 end
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 83 def required(value = true) 84 @option.required = value 85 end