Method: Jets::Commands::Base.autocomplete

Defined in:
lib/jets/commands/base.rb

.autocomplete(full_command) ⇒ Object

If this fails to find a match then return the original full command



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/jets/commands/base.rb', line 112

def autocomplete(full_command)
  return nil if full_command.nil? # jets help

  eager_load!

  words = full_command.split(':')
  namespace = words[0..-2].join(':') if words.size > 1
  command = words.last

  # Thor's normalize_command_name autocompletes the command but then we need to add the namespace back
  begin
    thor_subclass = klass_from_namespace(namespace) # could NameError
    command = thor_subclass.normalize_command_name(command) # could Thor::AmbiguousCommandError
    [namespace, command].compact.join(':')
  rescue NameError
    full_command # return original full_command
  rescue Thor::AmbiguousCommandError => e
    puts "Unable to autodetect the command name. #{e.message}."
    full_command # return original full_command
  end
end