Class: Dry::CLI::Autocomplete::Emitters::Bash
- Inherits:
-
Object
- Object
- Dry::CLI::Autocomplete::Emitters::Bash
- Defined in:
- lib/dry/cli/autocomplete/emitters/bash.rb
Overview
Turns a CompletionSpec into a bash complete -F script.
See SPECIFICATION.md §4.1: a static, case-statement walk over
COMP_WORDS resolves which node the cursor is under, then
compgen -W fills COMPREPLY from that node's children and
option flags, with compgen -f added where an argument is a
file (§4.3).
Deliberately avoids bash associative arrays (bash 4+ only): macOS still ships bash 3.2 as /bin/bash, and this script is meant to be eval'd from exactly that.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(spec) ⇒ Bash
constructor
A new instance of Bash.
Constructor Details
#initialize(spec) ⇒ Bash
Returns a new instance of Bash.
24 25 26 |
# File 'lib/dry/cli/autocomplete/emitters/bash.rb', line 24 def initialize(spec) @spec = spec end |
Class Method Details
.call(spec) ⇒ Object
20 21 22 |
# File 'lib/dry/cli/autocomplete/emitters/bash.rb', line 20 def self.call(spec) new(spec).call end |
Instance Method Details
#call ⇒ Object
28 29 30 |
# File 'lib/dry/cli/autocomplete/emitters/bash.rb', line 28 def call "#{body.join("\n")}\n" end |