What is @oclif/plugin-autocomplete?
@oclif/plugin-autocomplete is a plugin for the Oclif CLI framework that provides autocomplete functionality for CLI commands. It helps users by suggesting command completions, options, and arguments as they type, improving the user experience and efficiency.
What are @oclif/plugin-autocomplete's main functionalities?
Enable Autocomplete
This feature enables autocomplete for the CLI application. The code sample demonstrates how to enable autocomplete using the @oclif/plugin-autocomplete package.
const { Command } = require('@oclif/core');
const Autocomplete = require('@oclif/plugin-autocomplete').default;
class MyCommand extends Command {
async run() {
this.log('Enabling autocomplete...');
await Autocomplete.enable();
}
}
MyCommand.run();
Generate Autocomplete Script
This feature generates the autocomplete script for the CLI application. The code sample shows how to generate and log the autocomplete script using the @oclif/plugin-autocomplete package.
const { Command } = require('@oclif/core');
const Autocomplete = require('@oclif/plugin-autocomplete').default;
class MyCommand extends Command {
async run() {
this.log('Generating autocomplete script...');
const script = await Autocomplete.generate();
this.log(script);
}
}
MyCommand.run();
Disable Autocomplete
This feature disables autocomplete for the CLI application. The code sample demonstrates how to disable autocomplete using the @oclif/plugin-autocomplete package.
const { Command } = require('@oclif/core');
const Autocomplete = require('@oclif/plugin-autocomplete').default;
class MyCommand extends Command {
async run() {
this.log('Disabling autocomplete...');
await Autocomplete.disable();
}
}
MyCommand.run();
Other packages similar to @oclif/plugin-autocomplete
commander
Commander is a popular CLI framework for Node.js that provides command parsing and option handling. While it does not natively support autocomplete, it can be extended with additional packages to provide similar functionality. Compared to @oclif/plugin-autocomplete, Commander requires more setup to achieve autocomplete features.
yargs
Yargs is another CLI framework for Node.js that helps build interactive command-line tools. It includes some built-in support for command completion, but it is not as comprehensive as @oclif/plugin-autocomplete. Yargs is more focused on argument parsing and validation.
inquirer
Inquirer is a library for creating interactive command-line interfaces. It provides prompts and questions to guide users through command execution. While it does not offer autocomplete, it can be used alongside other packages to enhance the user experience. Inquirer is more focused on user interaction rather than command completion.
@oclif/plugin-autocomplete
autocomplete plugin for oclif (bash, zsh and powershell)
Usage
Run <cli> autocomplete
to generate the autocomplete files for your current shell.
Topic separator
Since oclif v2 it's possible to use spaces as a topic separator in addition to colons.
For bash and zsh each topic separator has different autocomplete implementations, if the CLI supports using a space as the separator, plugin-autocomplete will generate completion for that topic.
If you still want to use the colon-separated autocomplete you can set OCLIF_AUTOCOMPLETE_TOPIC_SEPARATOR
to colon
and re-generate the autocomplete files.
Docs: https://oclif.io/docs/topic_separator
Commands
oclif-example autocomplete [SHELL]
Display autocomplete installation instructions.
USAGE
$ oclif-example autocomplete [SHELL] [-r]
ARGUMENTS
SHELL (zsh|bash|powershell) Shell type
FLAGS
-r, --refresh-cache Refresh cache (ignores displaying instructions)
DESCRIPTION
Display autocomplete installation instructions.
EXAMPLES
$ oclif-example autocomplete
$ oclif-example autocomplete bash
$ oclif-example autocomplete zsh
$ oclif-example autocomplete powershell
$ oclif-example autocomplete --refresh-cache
See code: src/commands/autocomplete/index.ts
Contributing
See contributing guide