Class: HammerCLI::Bash::Completion
- Inherits:
-
Object
- Object
- HammerCLI::Bash::Completion
- Defined in:
- lib/hammer_cli/bash/completion.rb
Class Method Summary collapse
Instance Method Summary collapse
- #complete(line) ⇒ Object
-
#initialize(dict) ⇒ Completion
constructor
A new instance of Completion.
Constructor Details
#initialize(dict) ⇒ Completion
Returns a new instance of Completion.
6 7 8 |
# File 'lib/hammer_cli/bash/completion.rb', line 6 def initialize(dict) @dict = dict end |
Class Method Details
.load_description(path) ⇒ Object
22 23 24 25 26 |
# File 'lib/hammer_cli/bash/completion.rb', line 22 def self.load_description(path) JSON.load(File.open(path)) rescue Errno::ENOENT {} end |
Instance Method Details
#complete(line) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hammer_cli/bash/completion.rb', line 10 def complete(line) @complete_line = line.end_with?(' ') full_path = line.split(' ') complete_path = @complete_line ? full_path : full_path[0..-2] dict, path = traverse_tree(@dict, complete_path) return [] unless path.empty? # lost during traversing partial = @complete_line ? '' : full_path.last finish_word(dict, partial) end |