Yargs: Question: How do I handle invalid/unknown commands?

Created on 1 May 2017  路  2Comments  路  Source: yargs/yargs

I'm using yargs with .commandDir(). When an unknown/invalid subcommand is called, yargs seemingly does nothing. Is there a way to catch this? I think the best thing to do here would be display usage, but I don't see any hooks to be able to do that.

Most helpful comment

@fearphage if on the top-level yargs object you set: .strict() it will start reporting an error when an unknown command is used.

Would it be helpful if we updated the documentation for strict() to mention that it requires known commands? would happily accept a patch for this.

All 2 comments

@fearphage if on the top-level yargs object you set: .strict() it will start reporting an error when an unknown command is used.

Would it be helpful if we updated the documentation for strict() to mention that it requires known commands? would happily accept a patch for this.

Thanks for the prompt response. I agree the documentation around this could be punched up a bit.

Was this page helpful?
0 / 5 - 0 ratings