7 ms·
This article goes through discussing using tjs commander library for building node cli’s. I’m not a big fan of the library. A recent approach I’ve been taking
by navd 8y ago
This article goes through discussing using tjs commander library for building node cli’s. I’m not a big fan of the library.
A recent approach I’ve been taking is just parsing args with something like minimist or zeit/arg and then handling the commands passed in.
It leads to a lot simpler code especially for small tasks like what is described in the parent article.
Another tip, you could also use pkg to create binaries for your new cli application so people don’t need node installed on their machine to run them.
- abritinthebay 8y agoI'm curious as to what you mean by simpler code? Commander leads to incredibly simple code (as it just sets a list of options) combined with helpful CLI help output.
- jessaustin 8y agoSome of the meaning of the code is embedded in how commander is set up, which if one is unfamiliar with it means the code is less explicit. Explicit is good, and there is a sense in which explicitness leads to simplicity.
- navd 8y agoExactly, it’s a lot clearer to your future self, and any other maintainers how the application works when you aren’t adhering to a “frameworks” way of doing something. Especially for a simple cli. Abstractions can be good, but I feel as though something like commander is really just an unneccessary abstraction. I’ll take simplicity first anyday.
- abritinthebay 8y agoIt’s extren explicit...? Each option is laid out clearly. Each option Maps to a key on the object that is passed to the function called at the end of a commander chain. It would be hard to be more explicit