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/2.0.0 darwin-x64 node-v12.22.6
$ oclif-example --help [COMMAND]
USAGE
$ oclif-example COMMAND
...
Commands
oclif-example commands
list all the commands
USAGE
$ oclif-example commands [-h] [-j] [--hidden] [--columns <value> | -x] [--sort <value>] [--filter <value>]
[--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
FLAGS
-h, --help show CLI help
-j, --json display unfiltered api data in json format
-x, --extended show extra columns
--columns=<value> only show provided columns (comma-separated)
--csv output is csv format [alias: --output=csv]
--filter=<value> filter property by partial string matching, ex: name=foo
--hidden show hidden commands
--no-header hide table header from output
--no-truncate do not truncate output to fit screen
--output=<option> output in a more machine friendly format
<options: csv|json|yaml>
--sort=<value> property to sort by (prepend '-' for descending)
DESCRIPTION
list all the commands
See code: src/commands/commands.ts