Method: CommandKit::Options::Option#initialize

Defined in:
lib/command_kit/options/option.rb

#initialize(name, short: nil, long: self.class.default_long_opt(name), equals: false, value: nil, desc:) {|(value)| ... } ⇒ Option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the option.

Parameters:

  • name (Symbol)

    The name of the option.

  • short (String, nil) (defaults to: nil)

    Optional short-flag for the option.

  • long (String, nil) (defaults to: self.class.default_long_opt(name))

    Optional explicit long-flag for the option.

  • equals (Boolean) (defaults to: false)

    Specifies whether the option is of the form (--opt=value).

  • value (Hash{Symbol => Object}, true, false, nil) (defaults to: nil)

    Keyword arguments for CommandKit::Options::OptionValue#initialize, or nil if the option has no additional value.

  • desc (String)

    The description for the option.

Options Hash (value:):

  • type (Class, Hash, Array, Regexp)

    The type of the option's value.

  • usage (String, nil)

    The usage string for the option's value.

Yields:

  • ((value))

    If a block is given, it will be called when the option is parsed.

Yield Parameters:

  • value (Object, nil)

    The given block will be passed the parsed option's value.

Raises:

  • (TypeError)

    The value keyword argument was not a Hash, true, false, or nil.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/command_kit/options/option.rb', line 86

def initialize(name, short:   nil,
                     long:    self.class.default_long_opt(name),
                     equals:  false,
                     value:   nil,
                     desc:    ,
                     &block)
  @name    = name
  @short   = short
  @long    = long
  @equals  = equals
  @value   = case value
             when Hash       then OptionValue.new(**value)
             when true       then OptionValue.new()
             when false, nil then nil
             else
               raise(TypeError,"value: keyword must be Hash, true, false, or nil")
             end
  @desc    = desc
  @block   = block
end