Module: Importmap
- Extended by:
- Importmap
- Included in:
- Importmap
- Defined in:
- lib/importmap/completer.rb,
lib/importmap.rb,
lib/importmap/cli.rb,
lib/importmap/npm.rb,
lib/importmap/command.rb,
lib/importmap/version.rb,
lib/importmap/packager.rb,
lib/importmap/framework.rb,
lib/importmap/autoloader.rb
Overview
Code Explanation:
There are 3 types of things to auto-complete:
1. command: the command itself
2. parameters: command parameters.
3. options: command options
Here’s an example:
mycli hello name --from me
* command: hello
* parameters: name
* option: --from
When command parameters are done processing, the remaining completion words will be options. We can tell that the command params are completed based on the method arity.
## Arity
For example, say you had a method for a CLI command with the following form:
CLI COMMAND service count --cluster development
It’s equivalent ruby method:
scale(service, count) = has an arity of 2
So typing:
CLI COMMAND service count [TAB] # there are 3 parameters including the "scale" command according to Thor's CLI processing.
So the completion should only show options, something like this:
--noop --verbose --cluster
## Splat Arguments
When the ruby method has a splat argument, it’s arity is negative. Here are some example methods and their arities.
ship(service) = 1
scale(service, count) = 2
foo(example, *rest) = -2
Fortunately, negative and positive arity values are processed the same way. So we take simply take the absolute value of the arity and process it the same.
Here are some test cases, hit TAB after typing the command:
importmap completion
importmap completion hello
importmap completion hello name
importmap completion hello name --
importmap completion hello name --noop
importmap completion
importmap completion sub:goodbye
importmap completion sub:goodbye name
## Subcommands and Thor::Group Registered Commands
Sometimes the commands are not simple thor commands but are subcommands or Thor::Group commands. A good specific example is the CLI COMMAND.
* regular command: CLI COMMAND
* subcommand: CLI COMMAND
* Thor::Group command: CLI COMMAND
Auto-completion accounts for each of these type of commands.
Defined Under Namespace
Classes: Autoloader, CLI, Command, Completer, Error, Framework, Map, Npm, Packager, Reloader
Constant Summary collapse
- VERSION =
"0.1.0"