Method: CLASP::OptionSpecification#initialize
- Defined in:
- lib/clasp/specifications.rb
#initialize(name, aliases, help, values_range, default_value, required, required_message, constraint, extras = nil, &blk) ⇒ OptionSpecification
Creates an OptionSpecification 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, which will be used in the case where an option is specified without a value. May benil -
required(boolean) Whether the option is required. May benil -
required_message(::String) Message to be used when reporting that a required option is missing. May benilin 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 message -
constraint(Hash) Constraint to be applied to the parsed values of options matching this specification. NOTE: only integer constraints are supported in the current version -
extrasAn application-defined additional parameter. Ifnil, it is assigned an emptyHash
-
-
Block An optional block that is called when a matching option argument is found
NOTE: Users should prefer the CLASP::Option() method
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/clasp/specifications.rb', line 240 def initialize(name, aliases, help, values_range, default_value, required, , constraint, extras = nil, &blk) check_arity_(blk, 0..3, "option") @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @values_range = values_range || [] @default_value = default_value @required = required @required_message = nil @constraint = constraint || {} @extras = extras || {} @action = blk 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 @required_message = end |