Class: Toys::Flag
- Inherits:
-
Object
- Object
- Toys::Flag
- Defined in:
- core-docs/toys/flag.rb
Overview
Defined in the toys-core gem
Representation of a formal set of flags that set a particular context key. The flags within a single Flag definition are synonyms.
Defined Under Namespace
Classes: DefaultCompletion, Resolution, Syntax
Constant Summary collapse
- SET_HANDLER =
The set handler replaces the previous value.
proc { |val| val }
- PUSH_HANDLER =
The push handler pushes the given value using the
<<operator. proc { |val, prev| prev.nil? ? [val] : prev << val }
- DEFAULT_HANDLER =
The default handler is the set handler, which replaces the previous value.
SET_HANDLER
Instance Attribute Summary collapse
-
#acceptor ⇒ Toys::Acceptor::Base
readonly
Returns the effective acceptor.
-
#default ⇒ Object
readonly
Returns the default value, which may be
nil. -
#desc ⇒ Toys::WrappableString
The short description string.
-
#display_name ⇒ String
readonly
The display name of this flag.
-
#flag_completion ⇒ Proc, Toys::Completion::Base
readonly
The proc that determines shell completions for the flag.
-
#flag_syntax ⇒ Array<Toys::Flag::Syntax>
readonly
Returns an array of Flag::Syntax for the flags.
-
#flag_type ⇒ :boolean, :value
readonly
The type of flag.
-
#group ⇒ Toys::FlagGroup
readonly
Returns the flag group containing this flag.
-
#handler ⇒ Proc
readonly
The handler for setting/updating the value.
-
#key ⇒ Symbol
readonly
Returns the key.
-
#long_desc ⇒ Array<Toys::WrappableString>
The long description strings.
-
#sort_str ⇒ String
readonly
A string that can be used to sort this flag.
-
#value_completion ⇒ Proc, Toys::Completion::Base
readonly
The proc that determines shell completions for the value.
-
#value_delim ⇒ String?
readonly
The value delimiter, which may be
""," ", or"=". -
#value_label ⇒ String?
readonly
The string label for the value as it should display in help.
-
#value_type ⇒ :required, ...
readonly
The type of value.
Class Method Summary collapse
-
.create(key, flags = [], used_flags: nil, report_collisions: true, accept: nil, handler: nil, default: nil, complete_flags: nil, complete_values: nil, display_name: nil, desc: nil, long_desc: nil, group: nil) ⇒ Object
Create a flag definition.
Instance Method Summary collapse
-
#active? ⇒ boolean
Whether this flag is active--that is, it has a nonempty flags list.
-
#append_long_desc(long_desc) ⇒ self
Append long description strings.
-
#canonical_syntax_strings ⇒ Array<String>
A list of canonical flag syntax strings.
-
#effective_flags ⇒ Array<String>
The list of all effective flags used.
-
#long_flag_syntax ⇒ Array<Flag::Syntax>
An array of Flag::Syntax including only long (double-dash) flags.
-
#resolve(str) ⇒ Toys::Flag::Resolution
Look up the flag by string.
-
#short_flag_syntax ⇒ Array<Flag::Syntax>
An array of Flag::Syntax including only short (single dash) flags.
Instance Attribute Details
#acceptor ⇒ Toys::Acceptor::Base (readonly)
Returns the effective acceptor.
366 367 368 |
# File 'core-docs/toys/flag.rb', line 366 def acceptor @acceptor end |
#default ⇒ Object (readonly)
Returns the default value, which may be nil.
372 373 374 |
# File 'core-docs/toys/flag.rb', line 372 def default @default end |
#desc ⇒ Toys::WrappableString
The short description string.
When reading, this is always returned as a WrappableString.
When setting, the description may be provided as any of the following:
- A WrappableString.
- A normal String, which will be transformed into a WrappableString using spaces as word delimiters.
- An Array of String, which will be transformed into a WrappableString where each array element represents an individual word for wrapping.
389 390 391 |
# File 'core-docs/toys/flag.rb', line 389 def desc @desc end |
#display_name ⇒ String (readonly)
The display name of this flag.
466 467 468 |
# File 'core-docs/toys/flag.rb', line 466 def display_name @display_name end |
#flag_completion ⇒ Proc, Toys::Completion::Base (readonly)
The proc that determines shell completions for the flag.
420 421 422 |
# File 'core-docs/toys/flag.rb', line 420 def flag_completion @flag_completion end |
#flag_syntax ⇒ Array<Toys::Flag::Syntax> (readonly)
Returns an array of Flag::Syntax for the flags.
360 361 362 |
# File 'core-docs/toys/flag.rb', line 360 def flag_syntax @flag_syntax end |
#flag_type ⇒ :boolean, :value (readonly)
The type of flag.
434 435 436 |
# File 'core-docs/toys/flag.rb', line 434 def flag_type @flag_type end |
#group ⇒ Toys::FlagGroup (readonly)
Returns the flag group containing this flag
348 349 350 |
# File 'core-docs/toys/flag.rb', line 348 def group @group end |
#handler ⇒ Proc (readonly)
The handler for setting/updating the value.
414 415 416 |
# File 'core-docs/toys/flag.rb', line 414 def handler @handler end |
#key ⇒ Symbol (readonly)
Returns the key.
354 355 356 |
# File 'core-docs/toys/flag.rb', line 354 def key @key end |
#long_desc ⇒ Array<Toys::WrappableString>
The long description strings.
When reading, this is returned as an Array of WrappableString representing the lines in the description.
When setting, the description must be provided as an Array where each element may be any of the following:
- A WrappableString representing one line.
- A normal String representing a line. This will be transformed into a WrappableString using spaces as word delimiters.
- An Array of String representing a line. This will be transformed into a WrappableString where each array element represents an individual word for wrapping.
408 409 410 |
# File 'core-docs/toys/flag.rb', line 408 def long_desc @long_desc end |
#sort_str ⇒ String (readonly)
A string that can be used to sort this flag
472 473 474 |
# File 'core-docs/toys/flag.rb', line 472 def sort_str @sort_str end |
#value_completion ⇒ Proc, Toys::Completion::Base (readonly)
The proc that determines shell completions for the value.
426 427 428 |
# File 'core-docs/toys/flag.rb', line 426 def value_completion @value_completion end |
#value_delim ⇒ String? (readonly)
The value delimiter, which may be "", " ", or "=".
460 461 462 |
# File 'core-docs/toys/flag.rb', line 460 def value_delim @value_delim end |
#value_label ⇒ String? (readonly)
The string label for the value as it should display in help.
452 453 454 |
# File 'core-docs/toys/flag.rb', line 452 def value_label @value_label end |
#value_type ⇒ :required, ... (readonly)
The type of value.
445 446 447 |
# File 'core-docs/toys/flag.rb', line 445 def value_type @value_type end |
Class Method Details
.create(key, flags = [], used_flags: nil, report_collisions: true, accept: nil, handler: nil, default: nil, complete_flags: nil, complete_values: nil, display_name: nil, desc: nil, long_desc: nil, group: nil) ⇒ Object
Create a flag definition.
337 338 339 340 341 342 |
# File 'core-docs/toys/flag.rb', line 337 def self.create(key, flags = [], used_flags: nil, report_collisions: true, accept: nil, handler: nil, default: nil, complete_flags: nil, complete_values: nil, display_name: nil, desc: nil, long_desc: nil, group: nil) # Source available in the toys-core gem end |
Instance Method Details
#active? ⇒ boolean
Whether this flag is active--that is, it has a nonempty flags list.
524 525 526 |
# File 'core-docs/toys/flag.rb', line 524 def active? # Source available in the toys-core gem end |
#append_long_desc(long_desc) ⇒ self
Append long description strings.
You must pass an array of lines in the long description. See #long_desc for details on how each line may be represented.
559 560 561 |
# File 'core-docs/toys/flag.rb', line 559 def append_long_desc(long_desc) # Source available in the toys-core gem end |
#canonical_syntax_strings ⇒ Array<String>
A list of canonical flag syntax strings.
515 516 517 |
# File 'core-docs/toys/flag.rb', line 515 def canonical_syntax_strings # Source available in the toys-core gem end |
#effective_flags ⇒ Array<String>
The list of all effective flags used.
494 495 496 |
# File 'core-docs/toys/flag.rb', line 494 def effective_flags # Source available in the toys-core gem end |
#long_flag_syntax ⇒ Array<Flag::Syntax>
An array of Flag::Syntax including only long (double-dash) flags.
486 487 488 |
# File 'core-docs/toys/flag.rb', line 486 def long_flag_syntax # Source available in the toys-core gem end |
#resolve(str) ⇒ Toys::Flag::Resolution
Look up the flag by string. Returns an object that indicates whether the given string matched this flag, whether the match was unique, and other pertinent information.
506 507 508 |
# File 'core-docs/toys/flag.rb', line 506 def resolve(str) # Source available in the toys-core gem end |
#short_flag_syntax ⇒ Array<Flag::Syntax>
An array of Flag::Syntax including only short (single dash) flags.
478 479 480 |
# File 'core-docs/toys/flag.rb', line 478 def short_flag_syntax # Source available in the toys-core gem end |