applause-cli: A Node.js CLI handling library
Continuing in the theme of things I've forgotten to talk about, I'd like to post about another package I've released a little while ago. I've been building a number of command line interfaces for my PhD, so I thought it would be best to use a library for this function.
I found [clap
](), but it didn't quite do what I wanted - so I wrote my own inspired by it. Soon enough I needed to use the code in several different projects, so I abstracted the logic for it out and called it applause-cli
, which you can now find on npm.
It has no dependencies, and it allows you do define a set of arguments and have it parsed out the values from a given input array of items automatically. Here's an example of how it works:
import Program from 'applause-cli';
let program = new Program("path/to/package.json");
program.argument("food", "Specifies the food to find.", "apple")
.argument("count", "The number of items to find", 1, "number");
program.parse(process.argv.slice(2)); // Might return { food: "banana", count: 6 }
I even have automated documentation generated with documentation and uploaded to my website via Continuous Integration: https://starbeamrainbowlabs.com/code/applause-cli/. I've worked pretty hard on the documentation for this library actually - it even has integrated examples to show you how to use each function!
The library can also automatically generate help output from the provided information when the --help
argument is detected too - though I have yet to improve the output if a subcommand is called (e.g. mycommand dostuff --help
) - this is on my todo list :-)
Here's an example of the help text it automatically generates:
If this looks like something you'd be interested in using, I recommend checking out the npm package here: https://www.npmjs.com/package/applause-cli
For the curious, applause-cli is open-source under the MPL-2.0 licence. Find the code here: https://github.com/sbrl/applause-cli.