Class: CLASP::Option
- Inherits:
-
Object
- Object
- CLASP::Option
- Defined in:
- lib/clasp/aliases.rb
Overview
A class that represents the specification for a command-line option
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
The option’s aliases array.
-
#default_value ⇒ Object
readonly
The default value of the option.
-
#extras ⇒ Object
readonly
The option’s extras.
-
#help ⇒ Object
readonly
The option’s help string.
-
#name ⇒ Object
readonly
The option’s name string.
-
#required_message ⇒ Object
readonly
The message to be used when reporting that a required option is missing.
-
#values_range ⇒ Object
readonly
The range of values supported by the option.
Instance Method Summary collapse
-
#initialize(name, aliases, help, values_range, default_value, required, required_message, extras = nil) ⇒ Option
constructor
Creates an Option instance from the given name, aliases, help, values_range, and default_value.
-
#required? ⇒ Boolean
Indicates whether the option is required.
-
#to_s ⇒ Object
String form of the option.
Constructor Details
#initialize(name, aliases, help, values_range, default_value, required, required_message, extras = nil) ⇒ Option
Creates an Option instance from the given name, aliases, help, values_range, and default_value
Signature
-
Parameters
name-
(
String) The name, or long-form, of the option.
aliases-
(
Array) 0 or more strings specifying short-form or option-value aliases.
help-
(
String) The help string, which may benil.
values_range-
(
Array) 0 or more strings specifying values supported by the option.
default_value-
(
String) The default value of the option. May benil.
required- boolean
-
Whether the option is required. May be
nilrequired_message- ::String
-
Message to be used when reporting
that a required option is missing. May be
nilin which case a message of the form “<option-name> not specified; use –help for usage”. If begins with the nul character (“0”), then is used in the place of the <option-name> and placed into the rest of the standard form messageextras-
An application-defined additional parameter. If
nil, it is assigned an emptyHash.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/clasp/aliases.rb', line 143 def initialize(name, aliases, help, values_range, default_value, required, , extras = nil) @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @values_range = values_range || [] @default_value = default_value @required = required = nil @extras = extras || {} rm_name = nil if if "\0" == [0] rm_name = [1..-1] end else rm_name = "'#{name}'" end if rm_name = "#{rm_name} not specified; use --help for usage" end = end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
The option’s aliases array
178 179 180 |
# File 'lib/clasp/aliases.rb', line 178 def aliases @aliases end |
#default_value ⇒ Object (readonly)
The default value of the option
184 185 186 |
# File 'lib/clasp/aliases.rb', line 184 def default_value @default_value end |
#extras ⇒ Object (readonly)
The option’s extras
191 192 193 |
# File 'lib/clasp/aliases.rb', line 191 def extras @extras end |
#help ⇒ Object (readonly)
The option’s help string
180 181 182 |
# File 'lib/clasp/aliases.rb', line 180 def help @help end |
#name ⇒ Object (readonly)
The option’s name string
176 177 178 |
# File 'lib/clasp/aliases.rb', line 176 def name @name end |
#required_message ⇒ Object (readonly)
The message to be used when reporting that a required option is missing
189 190 191 |
# File 'lib/clasp/aliases.rb', line 189 def end |
#values_range ⇒ Object (readonly)
The range of values supported by the option
182 183 184 |
# File 'lib/clasp/aliases.rb', line 182 def values_range @values_range end |
Instance Method Details
#required? ⇒ Boolean
Indicates whether the option is required
186 |
# File 'lib/clasp/aliases.rb', line 186 def required?; @required; end |
#to_s ⇒ Object
String form of the option
194 195 196 197 |
# File 'lib/clasp/aliases.rb', line 194 def to_s "{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; required?=#{required?}; extras=#{extras}}" end |