Skip to content

WIP: Reject excess arguments by default - #1399

Closed
shadowspawn wants to merge 2 commits into
tj:release/7.xfrom
shadowspawn:feature/allow-unknown-arguments
Closed

shadowspawn wants to merge 2 commits into
tj:release/7.xfrom
shadowspawn:feature/allow-unknown-arguments

Conversation

@shadowspawn

@shadowspawn shadowspawn commented Nov 21, 2020 •

Copy link
Copy Markdown
Collaborator

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

shadowspawn commented Nov 28, 2020 •

Copy link
Copy Markdown
Collaborator Author

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

shadowspawn commented Dec 30, 2020 •

Copy link
Copy Markdown
Collaborator Author

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