Class: HammerCLI::Completer

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/completer.rb

Instance Method Summary collapse

Constructor Details

#initialize(cmd_class) ⇒ Completer

Returns a new instance of Completer.



67
68
69
# File 'lib/hammer_cli/completer.rb', line 67

def initialize(cmd_class)
  @command = cmd_class
end

Instance Method Details

#complete(line) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/hammer_cli/completer.rb', line 71

def complete(line)
  line = CompleterLine.new(line)

  # get the last command on the line
  cmd, remaining = find_last_cmd(line)

  opt, value = option_to_complete(cmd, remaining)
  if opt
    return complete_attribute(opt, value)
  else
    param, value = param_to_complete(cmd, remaining)
    if param
      if remaining.complete?
        return complete_attribute(param, value) + complete_command(cmd, remaining)
      else
        return complete_attribute(param, value)
      end
    else
      return complete_command(cmd, remaining)
    end

  end
end