Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
commandpost
Advanced tools
commandpost is a command-line options parser. This library is inspired by commander.
commander is very user-friendly, but not TypeScript-friendly. commandpost aims to improve this. Of course, commandpost can also be used from an ordinary JavaScript program. :+1:
$ npm install --save commandpost
$ cat cli.ts
import * as commandpost from "commandpost";
let root = commandpost
.create<{ spice: string[]; }, { food: string; }>("dinner <food>")
.version("1.0.0", "-v, --version")
.description("today's dinner!")
.option("-s, --spice <name>", "What spice do you want? default: pepper")
.action((opts, args) => {
console.log(`Your dinner is ${args.food} with ${opts.spice[0] || "pepper"}!`);
});
commandpost
.exec(root, process.argv)
.catch(err => {
if (err instanceof Error) {
console.error(err.stack);
} else {
console.error(err);
}
process.exit(1);
});
$ node cli.js --help
Usage: dinner [options] [--] <food>
Options:
-s, --spice <name> What spice do you want? default: pepper
$ node cli.js -s "soy sause" "fillet steak"
Your dinner is fillet steak with soy sause!
A top-level command is created by the commandpost.create
function.
commandpost also supports sub-commands.
A sub-command is created by using the topLevelCommand.subCommand
method.
Refer to this example for a demonstration.
commandpost can automatically generate help and command usage messages based on your configuration. For best results, it is recommended that you should set .version
and .description
for your top-level command.
// shorthand & formal option with a required parameter. value is converted to string[].
cmd.option("-c, --config <configFile>", "Read setting from specified config file path");
// option with optional parameter. value is converted to string[].
cmd.option("-c, --config [configFile]", "Read setting from specified config file path");
// option without parameter (flag). option value is converted to boolean and defaults to `false`.
cmd.option("--suppress-warning", "Suppress warning");
// option with `--no-` prefix. option value is converted to boolean and defaults to true.
cmd.option("--no-type-checking", "Type checking disabled");
If you want to handle unknown options, you can use the .allowUnknownOption
method.
// required argument
commandpost.create<{}, { food: string; }>("dinner <food>");
// optional argument
commandpost.create<{}, { food: string; }>("dinner [food]");
// variadic argument
commandpost.create<{}, { foods: string[]; }>("dinner <food...>");
This package's author, vvakame, is not a native English speaker. My first language is Japanese. If you find incorrect English, please send me a pull request.
FAQs
commandline option parser
The npm package commandpost receives a total of 57,016 weekly downloads. As such, commandpost popularity was classified as popular.
We found that commandpost demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.