Class: SimpleScripting::TabCompletion

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_scripting/tab_completion.rb,
lib/simple_scripting/tab_completion/commandline_processor.rb

Overview

The naming of each of the the commandline units is not standard, therefore we establish the following arbitrary, but consistent, naming:

executable --option option_parameter argument

The commandline is divided into words, as Bash would split them. All the words, except the executable, compose an array that we call argv (as Ruby would do).

We define each name => value or name => value as pair.

In the context of a pair, each pair is composed of a key and a value.

Defined Under Namespace

Classes: CommandlineProcessor

Instance Method Summary collapse

Constructor Details

#initialize(switches_definition, output: $stdout) ⇒ TabCompletion

Returns a new instance of TabCompletion.



21
22
23
24
# File 'lib/simple_scripting/tab_completion.rb', line 21

def initialize(switches_definition, output: $stdout)
  @switches_definition = switches_definition
  @output = output
end

Instance Method Details

#complete(execution_target, source_commandline = ENV.fetch('COMP_LINE'), cursor_position = ENV.fetch('COMP_POINT').to_i) ⇒ Object

Currently, any completion suffix is ignored and stripped.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/simple_scripting/tab_completion.rb', line 28

def complete(execution_target, source_commandline=ENV.fetch('COMP_LINE'), cursor_position=ENV.fetch('COMP_POINT').to_i)
  commandline_processor = CommandlineProcessor.process_commandline(source_commandline, cursor_position, @switches_definition)

  if commandline_processor.completing_an_option?
    complete_option(commandline_processor, execution_target)
  elsif commandline_processor.parsing_error?
    return
  else # completing_a_value?
    complete_value(commandline_processor, execution_target)
  end
end