Class: Toys::Utils::CompletionEngine::Base
- Inherits:
-
Object
- Object
- Toys::Utils::CompletionEngine::Base
- Defined in:
- lib/toys/utils/completion_engine.rb
Overview
Base class for shell completion engines that use a
COMP_LINE / COMP_POINT protocol.
Subclasses must implement the private methods #shell_name and
#output_completions.
Instance Method Summary collapse
-
#initialize(cli) ⇒ Base
constructor
Create a completion engine.
-
#run ⇒ Integer
Perform completion in the current shell environment, which must include settings for the
COMP_LINEandCOMP_POINTenvironment variables.
Constructor Details
#initialize(cli) ⇒ Base
Create a completion engine.
25 26 27 |
# File 'lib/toys/utils/completion_engine.rb', line 25 def initialize(cli) @cli = cli end |
Instance Method Details
#run ⇒ Integer
Perform completion in the current shell environment, which must
include settings for the COMP_LINE and COMP_POINT environment
variables. Prints out completion candidates and returns a status code
indicating the result.
- 0 for success.
- 1 if completion failed.
- 2 if the environment is incorrect (e.g. expected environment variables not found)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/toys/utils/completion_engine.rb', line 42 def run return 2 if !::ENV.key?("COMP_LINE") || !::ENV.key?("COMP_POINT") line = ::ENV["COMP_LINE"].to_s point = ::ENV["COMP_POINT"].to_i point = line.length if point.negative? line = line[0, point] result = run_internal(line) if result output_completions(*result) 0 else 1 end end |