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

WIP: Reject excess arguments by default #1399

Closed

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Nov 21, 2020

Pull Request

Problem

By default, excess arguments are silently ignored. Checking manually is a bit tricky.

See: #259 #749 #1000 #1268

Solution

  • add a check for excess arguments before calling action handler
  • .allowExcessArguments() is like .allowUnknownOption() to suppress the new error
  • .command('*') arguments are not checked to maintain legacy behaviour

Other changes:

  • switch action handler from trailing parameters of "options/command" and undocumented "extraArgs", to "options/command" and "command". This will hopefully make it easier to switch to safer options stored separately.

To Do

  • command:* listener
  • single commands with no action handler
  • default command
  • refine messaging (not happy with "excess")

TypeScript, tests, README et al

ChangeLog

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Nov 21, 2020
@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Nov 28, 2020

I tried doing a couple of things at once here which I am thinking of as somewhat related. However, they are individually complicated and not certain to work out well. I'll close this and have another go at one thing at a time.

See #1407

@shadowspawn shadowspawn deleted the feature/allow-unknown-arguments branch December 2, 2020 06:09
@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Dec 30, 2020

I am finding this is breaking quite a lot of my unit tests (due to lazily not declaring arguments) and not picking up actual problems. I think for Commander v7 it would be better to make this an opt-in behaviour that is inherited to subcommands (so can easily turn it on for whole program). Command 7 has breaking changes with options storage and action handler parameters, so plenty else for users to deal with!

I'll think a bit more and do a PR for consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: major Releasing requires a major version bump, not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant