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.
300 301 302 303 304 305 306 |
# File 'lib/toys/flag.rb', line 300 def initialize(flag:, include_short: true, include_long: true, include_negative: true) super() @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.
339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/toys/flag.rb', line 339 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
320 321 322 |
# File 'lib/toys/flag.rb', line 320 def include_long? @include_long end |
#include_negative? ⇒ Boolean
Whether to include negative long flags
328 329 330 |
# File 'lib/toys/flag.rb', line 328 def include_negative? @include_negative end |
#include_short? ⇒ Boolean
Whether to include short flags
312 313 314 |
# File 'lib/toys/flag.rb', line 312 def include_short? @include_short end |