Class: Dry::CLI::Autocomplete::Emitters::Bash

Inherits:
Object
  • Object
show all
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

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

#callObject



28
29
30
# File 'lib/dry/cli/autocomplete/emitters/bash.rb', line 28

def call
  "#{body.join("\n")}\n"
end