Class: CommandKit::Options::Option Private
- Inherits:
-
Object
- Object
- CommandKit::Options::Option
- Defined in:
- lib/command_kit/options/option.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents a defined option.
Instance Attribute Summary collapse
-
#block ⇒ Proc?
readonly
private
The optional block that will receive the parsed option value.
-
#category ⇒ String?
readonly
private
The optional category to group the option under.
-
#long ⇒ String
readonly
private
The option's long-flag.
-
#name ⇒ Symbol
readonly
private
The option's name.
-
#short ⇒ String?
readonly
private
The option's optional short-flag.
-
#value ⇒ OptionValue?
readonly
private
The option value's type.
Class Method Summary collapse
-
.default_long_opt(name) ⇒ String
private
The default long option (ex:
--long-opt) for the given option name (ex::long_opt).
Instance Method Summary collapse
-
#default_value ⇒ Object?
private
The option value's default value.
-
#desc ⇒ String+
private
The option description.
-
#equals? ⇒ Boolean
private
Specifies if the option is of the form
--opt=VALUE. -
#initialize(name, short: nil, long: self.class.default_long_opt(name), equals: false, value: nil, desc:, category: nil) {|(value)| ... } ⇒ Option
constructor
private
Initializes the option.
-
#separator ⇒ '=', ...
private
The separator character between the option and option value.
-
#type ⇒ Class?
private
The option value's type.
-
#usage ⇒ Array<String>
private
Usage strings for the option.
-
#value? ⇒ Boolean
private
Determines if the option has a value.
Constructor Details
#initialize(name, short: nil, long: self.class.default_long_opt(name), equals: false, value: nil, desc:, category: nil) {|(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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/command_kit/options/option.rb', line 91 def initialize(name, short: nil, long: self.class.default_long_opt(name), equals: false, value: nil, desc: , category: nil, &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 @category = category @block = block end |
Instance Attribute Details
#block ⇒ Proc? (readonly)
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.
The optional block that will receive the parsed option value.
41 42 43 |
# File 'lib/command_kit/options/option.rb', line 41 def block @block end |
#category ⇒ String? (readonly)
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.
The optional category to group the option under.
48 49 50 |
# File 'lib/command_kit/options/option.rb', line 48 def category @category end |
#long ⇒ String (readonly)
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.
The option's long-flag.
31 32 33 |
# File 'lib/command_kit/options/option.rb', line 31 def long @long end |
#name ⇒ Symbol (readonly)
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.
The option's name.
21 22 23 |
# File 'lib/command_kit/options/option.rb', line 21 def name @name end |
#short ⇒ String? (readonly)
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.
The option's optional short-flag.
26 27 28 |
# File 'lib/command_kit/options/option.rb', line 26 def short @short end |
#value ⇒ OptionValue? (readonly)
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.
The option value's type.
36 37 38 |
# File 'lib/command_kit/options/option.rb', line 36 def value @value end |
Class Method Details
.default_long_opt(name) ⇒ String
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.
The default long option (ex: --long-opt) for the given option name
(ex: :long_opt).
124 125 126 |
# File 'lib/command_kit/options/option.rb', line 124 def self.default_long_opt(name) "--#{Inflector.dasherize(name)}" end |
Instance Method Details
#default_value ⇒ Object?
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.
The option value's default value.
187 188 189 |
# File 'lib/command_kit/options/option.rb', line 187 def default_value @value && @value.default_value end |
#desc ⇒ String+
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.
If #default_value returns a value, the description will contain the
Default: value the option will be initialized with.
The option description.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/command_kit/options/option.rb', line 200 def desc if (value = default_value) default_text = "(Default: #{value})" case @desc when Array @desc + [default_text] else "#{@desc} #{default_text}" end else @desc end end |
#equals? ⇒ Boolean
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.
Specifies if the option is of the form --opt=VALUE.
133 134 135 |
# File 'lib/command_kit/options/option.rb', line 133 def equals? @equals end |
#separator ⇒ '=', ...
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.
The separator character between the option and option value.
142 143 144 145 146 147 148 |
# File 'lib/command_kit/options/option.rb', line 142 def separator if @value if equals? then '=' else ' ' end end end |
#type ⇒ Class?
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.
The option value's type.
176 177 178 |
# File 'lib/command_kit/options/option.rb', line 176 def type @value && @value.type end |
#usage ⇒ Array<String>
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.
Usage strings for the option.
156 157 158 |
# File 'lib/command_kit/options/option.rb', line 156 def usage [*@short, "#{@long}#{separator}#{@value && @value.usage}"] end |
#value? ⇒ Boolean
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.
Determines if the option has a value.
165 166 167 |
# File 'lib/command_kit/options/option.rb', line 165 def value? !@value.nil? end |