Class: Toys::Flag::Syntax
- Inherits:
-
Object
- Object
- Toys::Flag::Syntax
- Defined in:
- lib/toys/flag.rb
Overview
Representation of a single flag.
Instance Attribute Summary collapse
-
#canonical_str ⇒ String
readonly
A canonical string representing this flag's syntax, normalized to match the type, delimiters, etc.
-
#flag_style ⇒ :long, :short
readonly
The style of flag (
:longor:short). -
#flag_type ⇒ :boolean, :value
readonly
The type of flag (
:booleanor:value). -
#flags ⇒ Array<String>
readonly
The flags (without values) corresponding to this syntax.
-
#negative_flag ⇒ String?
readonly
The flag (without values) corresponding to the "negative" form of this flag, if any.
-
#original_str ⇒ String
readonly
The original string that was parsed to produce this syntax.
-
#positive_flag ⇒ String
readonly
The flag (without values) corresponding to the normal "positive" form of this flag.
-
#sort_str ⇒ String
readonly
A string used to sort this flag compared with others.
-
#str_without_value ⇒ String
readonly
The original string with the value (if any) stripped, but retaining the
[no-]prefix if present. -
#value_delim ⇒ String?
readonly
The default delimiter used for the value of this flag.
-
#value_label ⇒ String?
readonly
The default "label" for the value.
-
#value_type ⇒ :required, ...
readonly
The type of value (
:requiredor:optional).
Instance Method Summary collapse
-
#initialize(str) ⇒ Syntax
constructor
Parse flag syntax.
Constructor Details
#initialize(str) ⇒ Syntax
Parse flag syntax
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/toys/flag.rb', line 477 def initialize(str) case str when /\A(-([\?\w]))\z/ setup(str, $1, nil, $1, $2, :short, nil, nil, nil, nil) when /\A(-([\?\w]))( ?)\[(\w+)\]\z/ setup(str, $1, nil, $1, $2, :short, :value, :optional, $3, $4) when /\A(-([\?\w]))\[( )(\w+)\]\z/ setup(str, $1, nil, $1, $2, :short, :value, :optional, $3, $4) when /\A(-([\?\w]))( ?)(\w+)\z/ setup(str, $1, nil, $1, $2, :short, :value, :required, $3, $4) when /\A--\[no-\](\w[\?\w-]*)\z/ setup(str, "--#{$1}", "--no-#{$1}", str, $1, :long, :boolean, nil, nil, nil) when /\A(--(\w[\?\w-]*))\z/ setup(str, $1, nil, $1, $2, :long, nil, nil, nil, nil) when /\A(--(\w[\?\w-]*))([= ])\[(\w+)\]\z/ setup(str, $1, nil, $1, $2, :long, :value, :optional, $3, $4) when /\A(--(\w[\?\w-]*))\[([= ])(\w+)\]\z/ setup(str, $1, nil, $1, $2, :long, :value, :optional, $3, $4) when /\A(--(\w[\?\w-]*))([= ])(\w+)\z/ setup(str, $1, nil, $1, $2, :long, :value, :required, $3, $4) else raise ToolDefinitionError, "Illegal flag: #{str.inspect}" end end |
Instance Attribute Details
#canonical_str ⇒ String (readonly)
A canonical string representing this flag's syntax, normalized to match the type, delimiters, etc. settings of other flag syntaxes. This is generally used in help strings to represent this flag.
590 591 592 |
# File 'lib/toys/flag.rb', line 590 def canonical_str @canonical_str end |
#flag_style ⇒ :long, :short (readonly)
The style of flag (:long or :short).
551 552 553 |
# File 'lib/toys/flag.rb', line 551 def flag_style @flag_style end |
#flag_type ⇒ :boolean, :value (readonly)
The type of flag (:boolean or :value)
558 559 560 |
# File 'lib/toys/flag.rb', line 558 def flag_type @flag_type end |
#flags ⇒ Array<String> (readonly)
The flags (without values) corresponding to this syntax.
514 515 516 |
# File 'lib/toys/flag.rb', line 514 def flags @flags end |
#negative_flag ⇒ String? (readonly)
The flag (without values) corresponding to the "negative" form of this
flag, if any. i.e. if the original string was "--[no-]abc", the
negative flag is "--no-abc".
530 531 532 |
# File 'lib/toys/flag.rb', line 530 def negative_flag @negative_flag end |
#original_str ⇒ String (readonly)
The original string that was parsed to produce this syntax.
508 509 510 |
# File 'lib/toys/flag.rb', line 508 def original_str @original_str end |
#positive_flag ⇒ String (readonly)
The flag (without values) corresponding to the normal "positive" form of this flag.
521 522 523 |
# File 'lib/toys/flag.rb', line 521 def positive_flag @positive_flag end |
#sort_str ⇒ String (readonly)
A string used to sort this flag compared with others.
543 544 545 |
# File 'lib/toys/flag.rb', line 543 def sort_str @sort_str end |
#str_without_value ⇒ String (readonly)
The original string with the value (if any) stripped, but retaining
the [no-] prefix if present.
537 538 539 |
# File 'lib/toys/flag.rb', line 537 def str_without_value @str_without_value end |
#value_delim ⇒ String? (readonly)
The default delimiter used for the value of this flag. This could be
"" or " " for a short flag, or " " or "=" for a long flag.
574 575 576 |
# File 'lib/toys/flag.rb', line 574 def value_delim @value_delim end |
#value_label ⇒ String? (readonly)
The default "label" for the value. e.g. in --abc=VAL the label is
"VAL".
582 583 584 |
# File 'lib/toys/flag.rb', line 582 def value_label @value_label end |
#value_type ⇒ :required, ... (readonly)
The type of value (:required or :optional)
566 567 568 |
# File 'lib/toys/flag.rb', line 566 def value_type @value_type end |