Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable validation for a specific command #888

Closed
mikeerickson opened this issue Nov 15, 2018 · 3 comments
Closed

Disable validation for a specific command #888

mikeerickson opened this issue Nov 15, 2018 · 3 comments

Comments

@mikeerickson
Copy link

I am looking for a way to disable option validation on a per command basis?

program
  .command("up")
  .action((env, options) => {
});

Then, when calling command, I dont want commander to throw error with invalid options

$ cli up -dl --flags --logs ...

When calling up I receive message

error: unknown option `-l'
error: unknown option `--flags'
...
@shadowspawn
Copy link
Collaborator

shadowspawn commented Nov 21, 2018

You can use allowUnknownOption() which does just what you want, but be warned there is not a convenient way to get the unrecognised options. See example and discussion in #802.

An alternative pattern which might make sense if the options are for another command is to use -- to stop the option processing (which effectively turns the following options into arguments). I use this pattern a bit, like when passing options to an npm run script which are intended for the script and not for npm.

e.g.

program
.command("up [args...]")
.action((args) => {
    console.log(args);
});

Called like:

$ cli up -- -dl --flags --logs ...

@shadowspawn
Copy link
Collaborator

Did you sort out your problem? (Can this issue be closed?)

@shadowspawn
Copy link
Collaborator

Question hopefully answered. No further questions. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants