What is @oclif/plugin-commands?
@oclif/plugin-commands is a plugin for the Oclif CLI framework that provides functionality to list and manage commands within an Oclif-based CLI application. It helps developers to easily display available commands, their descriptions, and usage information.
What are @oclif/plugin-commands's main functionalities?
List Commands
This feature allows you to list all available commands in your CLI application. The code sample demonstrates how to use the @oclif/plugin-commands to display a table of commands with their names and descriptions.
const {Command} = require('@oclif/command');
const {cli} = require('cli-ux');
class ListCommands extends Command {
async run() {
const commands = this.config.commands;
cli.table(commands, {
name: {
header: 'Command Name'
},
description: {
header: 'Description'
}
});
}
}
ListCommands.description = 'List all available commands';
module.exports = ListCommands;
Command Help
This feature provides detailed help for a specific command. The code sample shows how to use the @oclif/plugin-commands to display help information for a command named 'mycommand'.
const {Command} = require('@oclif/command');
const {Help} = require('@oclif/plugin-help');
class CommandHelp extends Command {
async run() {
const help = new Help(this.config);
help.showHelp(['mycommand']);
}
}
CommandHelp.description = 'Show help for a specific command';
module.exports = CommandHelp;
Other packages similar to @oclif/plugin-commands
commander
Commander is a popular library for building command-line interfaces in Node.js. It provides a simple and flexible way to define commands, options, and arguments. Compared to @oclif/plugin-commands, Commander is more lightweight and does not offer built-in support for listing and managing commands, but it is highly customizable and widely used.
yargs
Yargs is another widely-used library for building command-line interfaces in Node.js. It provides a rich set of features for parsing arguments, defining commands, and generating help messages. While Yargs offers similar functionalities to @oclif/plugin-commands, it is more focused on argument parsing and does not provide the same level of integration with the Oclif framework.
vorpal
Vorpal is a CLI framework that allows developers to build interactive command-line applications. It provides features for defining commands, arguments, and options, as well as support for interactive prompts. Vorpal is similar to @oclif/plugin-commands in terms of command management, but it also includes additional features for creating interactive experiences.
@oclif/plugin-commands
plugin to show the list of all the commands
Usage
$ npm install -g @oclif/plugin-commands
$ oclif-example COMMAND
running command...
$ oclif-example (--version)
@oclif/plugin-commands/4.0.4 linux-x64 node-v20.14.0
$ oclif-example --help [COMMAND]
USAGE
$ oclif-example COMMAND
...
Commands
oclif-example commands
List all oclif-example commands.
USAGE
$ oclif-example commands [--json] [-c id|plugin|summary|type... | --tree] [--deprecated] [-x | ] [--hidden]
[--no-truncate | ] [--sort id|plugin|summary|type | ]
FLAGS
-c, --columns=<option>... Only show provided columns (comma-separated).
<options: id|plugin|summary|type>
-x, --extended Show extra columns.
--deprecated Show deprecated commands.
--hidden Show hidden commands.
--no-truncate Do not truncate output.
--sort=<option> [default: id] Property to sort by.
<options: id|plugin|summary|type>
--tree Show tree of commands.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
List all oclif-example commands.
See code: src/commands/commands.ts
Contributing
See contributing guide