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.
303 304 305 306 307 308 309 |
# File 'lib/toys/flag.rb', line 303 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.
342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/toys/flag.rb', line 342 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
323 324 325 |
# File 'lib/toys/flag.rb', line 323 def include_long? @include_long end |
#include_negative? ⇒ Boolean
Whether to include negative long flags
331 332 333 |
# File 'lib/toys/flag.rb', line 331 def include_negative? @include_negative end |
#include_short? ⇒ Boolean
Whether to include short flags
315 316 317 |
# File 'lib/toys/flag.rb', line 315 def include_short? @include_short end |