Class: CLASP::Arguments
- Inherits:
-
Object
- Object
- CLASP::Arguments
- Defined in:
- lib/clasp/arguments.rb
Overview
The main class for processing command-line arguments
Defined Under Namespace
Classes: Flag, ImmutableArray, Option
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
an immutable array of aliases.
-
#argv ⇒ Object
readonly
the (possibly mutated) array of arguments instance passed to new.
-
#argv_original_copy ⇒ Object
readonly
unchanged copy of the original array of arguments passed to new.
-
#flags ⇒ Object
readonly
an immutable array of flags.
-
#options ⇒ Object
readonly
an immutable array of options.
-
#values ⇒ Object
readonly
an immutable array of values.
Instance Method Summary collapse
-
#initialize(argv = ARGV, aliases = nil, options = {}) ⇒ Arguments
constructor
Constructs an instance of the class, according to the given parameters.
Constructor Details
#initialize(argv = ARGV, aliases = nil, options = {}) ⇒ Arguments
Constructs an instance of the class, according to the given parameters
See the documentation for the ::CLASP module for examples
Signature
-
Parameters:
argv
-
(
Array
) The arguments array. May not benil
. Defaults toARGV
.
aliases
-
(
Array
) The aliases array. Defaults tonil
. If none supplied, no aliasing will be performed.
options
-
An options hash, containing any of the following options.
-
Options:
mutate_arg:
-
(
Boolean
) Determines if the library should mutateargv
. Defaults totrue
. This is essential when using CLASP in conjunction with$<
.
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 275 276 277 278 279 |
# File 'lib/clasp/arguments.rb', line 243 def initialize(argv = ARGV, aliases = nil, = {}) # have to do this name-swap, as 'options' has CLASP-specific # meaning init_opts, = .dup, nil init_opts[:mutate_argv] = true unless init_opts.has_key? :mutate_argv @argv = argv @argv_original_copy = ImmutableArray.new(argv.dup) @aliases = aliases aliases = nil if aliases and aliases.empty? flags, , values = Arguments.parse(argv, aliases) @flags = ImmutableArray.new(flags) @options = ImmutableArray.new() @values = ImmutableArray.new(values) # do argv-mutation, if required if init_opts[:mutate_argv] while not argv.empty? argv.shift end @values.each do |v| argv << v end end end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
an immutable array of aliases
418 419 420 |
# File 'lib/clasp/arguments.rb', line 418 def aliases @aliases end |
#argv ⇒ Object (readonly)
the (possibly mutated) array of arguments instance passed to new
430 431 432 |
# File 'lib/clasp/arguments.rb', line 430 def argv @argv end |
#argv_original_copy ⇒ Object (readonly)
unchanged copy of the original array of arguments passed to new
433 434 435 |
# File 'lib/clasp/arguments.rb', line 433 def argv_original_copy @argv_original_copy end |
#flags ⇒ Object (readonly)
an immutable array of flags
421 422 423 |
# File 'lib/clasp/arguments.rb', line 421 def flags @flags end |
#options ⇒ Object (readonly)
an immutable array of options
424 425 426 |
# File 'lib/clasp/arguments.rb', line 424 def @options end |
#values ⇒ Object (readonly)
an immutable array of values
427 428 429 |
# File 'lib/clasp/arguments.rb', line 427 def values @values end |