Skip to content

Repeated flags fix#71

Merged
natecook1000 merged 1 commit into
apple:masterfrom
glessard:repeated-flags-fix
Mar 11, 2020
Merged

Repeated flags fix#71
natecook1000 merged 1 commit into
apple:masterfrom
glessard:repeated-flags-fix

Conversation

@glessard
Copy link
Copy Markdown
Contributor

@glessard glessard commented Mar 7, 2020

Stop failing upon seeing a repeated value from a mutually-exclusive set of flags.

This adds an Equatable requirement to the Flag constructors from CaseIterable enums. Given the other requirements on those enums, Equatable conformance is automatic and therefore costs nothing.

The switch statement in ArgumentSet.updateFlag is also much simplified, by calling values.element(forKey:) only when it is needed.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

This fixes #59
This supersedes #70

@glessard glessard mentioned this pull request Mar 7, 2020
4 tasks
@glessard
Copy link
Copy Markdown
Contributor Author

glessard commented Mar 7, 2020

Noting the draft PR #65, specifying the new EnumerableFlag to require Equatable would not be onerous, I think. It would be automatically generated in an overwhelming majority of uses.

@glessard glessard force-pushed the repeated-flags-fix branch from c85ce34 to 01b38e0 Compare March 7, 2020 19:24
@natecook1000
Copy link
Copy Markdown
Member

@glessard This looks great — I think adding the Equatable constraint is fine here, and I'll add that constraint to EnumerableFlag as well.

Can you update with latest and I'll merge?

- this is equivalent to saying the same thing twice, as opposed
  to contradicting oneself.
@glessard glessard force-pushed the repeated-flags-fix branch from 01b38e0 to 849c439 Compare March 11, 2020 00:50
@glessard
Copy link
Copy Markdown
Contributor Author

I rebased and squashed. Thanks!

@natecook1000 natecook1000 merged commit bbe4ec1 into apple:master Mar 11, 2020
griffin-stewie pushed a commit to griffin-stewie/swift-argument-parser that referenced this pull request Mar 11, 2020
- this is equivalent to saying the same thing twice, as opposed
  to contradicting oneself.
@glessard glessard deleted the repeated-flags-fix branch March 11, 2020 16:00
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

Successfully merging this pull request may close these issues.

Repeated flag causes error in some cases

2 participants