Skip to content

Throw error when no sub-command specified #942

@dland512

Description

@dland512

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions