My app always requires a sub command, e.g.
node main.js sub1
or
node main.js -x sub1
It's not valid to do
node main.js
or
node main.js -x
How can I catch this scenario? Is there a way to introspect the program object to tell if a sub command was used?
I was going to use process.argv.length but that doesn't really work because a user could still pass in options without a sub-command (node main.js -x -y -z). I can get around that by parsing porcess.argv more carefully but I was hoping there was a more supported way.
My app always requires a sub command, e.g.
node main.js sub1or
node main.js -x sub1It's not valid to do
node main.jsor
node main.js -xHow can I catch this scenario? Is there a way to introspect the
programobject to tell if a sub command was used?I was going to use
process.argv.lengthbut that doesn't really work because a user could still pass in options without a sub-command (node main.js -x -y -z). I can get around that by parsingporcess.argvmore carefully but I was hoping there was a more supported way.