Hacker News new | ask | show | jobs
by tln 2653 days ago
There are lots of different approaches to defining the arguments and options.

* You can build up a structure programmatically to define the arguments, as in commander, and then the usage and shape of the parsed result are implied.

* You can provide the usage, as in docopt, and then the structure to define the args and shape of the parsed result are implied.

* Or you can take the approach I did in fncli, which is to provide the shape of parsed result, as a function signature, and let the structure to define the args and usage be implied.

https://www.npmjs.com/package/fncli

This is possible because Javascript spec includes the function arguments as a string that can be parsed at run time.

Because you're using ES6 syntax, you don't have to learn a new syntax (unlike docli or docopt). And although there are limitations, I've found this approach to handle modest CLI needs with an absolute minimum of fuss.