Class: Toys::Flag::DefaultCompletion
- Inherits:
-
Completion::Base
- Object
- Completion::Base
- Toys::Flag::DefaultCompletion
- Defined in:
- lib/toys/flag.rb
Overview
A Completion that returns all possible flags associated with a Toys::Flag.
Instance Method Summary collapse
-
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
-
#include_long? ⇒ Boolean
Whether to include long flags.
-
#include_negative? ⇒ Boolean
Whether to include negative long flags.
-
#include_short? ⇒ Boolean
Whether to include short flags.
-
#initialize(flag:, include_short: true, include_long: true, include_negative: true) ⇒ DefaultCompletion
constructor
Create a completion given configuration options.
Constructor Details
#initialize(flag:, include_short: true, include_long: true, include_negative: true) ⇒ DefaultCompletion
Create a completion given configuration options.
733 734 735 736 737 738 |
# File 'lib/toys/flag.rb', line 733 def initialize(flag:, include_short: true, include_long: true, include_negative: true) @flag = flag @include_short = include_short @include_long = include_long @include_negative = include_negative end |
Instance Method Details
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/toys/flag.rb', line 771 def call(context) results = if @include_short && @include_long && @include_negative @flag.effective_flags else collect_results end fragment = context.fragment results.find_all { |val| val.start_with?(fragment) } .map { |str| Completion::Candidate.new(str) } end |
#include_long? ⇒ Boolean
Whether to include long flags
752 753 754 |
# File 'lib/toys/flag.rb', line 752 def include_long? @include_long end |
#include_negative? ⇒ Boolean
Whether to include negative long flags
760 761 762 |
# File 'lib/toys/flag.rb', line 760 def include_negative? @include_negative end |
#include_short? ⇒ Boolean
Whether to include short flags
744 745 746 |
# File 'lib/toys/flag.rb', line 744 def include_short? @include_short end |