-
Notifications
You must be signed in to change notification settings - Fork 336
Add an EnumerableFlag protocol #65
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
Conversation
This addresses the need for providing name specifications for enum flags, since property wrappers can't be used for enum cases.
b73d66d
to
6576bbc
Compare
@swift-ci Please test |
Co-authored-by: Kyle Macomber <[email protected]>
At first I thought the Array case was counter intuitive: enum Color: EnumerableFlag {
case pink, purple, silver
}
struct Example: ParsableCommand {
@Flag() var colors: [Color]
func run() throws {
print(colors)
}
}
... and was going to suggest it be broken out into a separate property wrapper, but I see the synergy with the Int use case. |
Seems like we could accept any |
We could definitely make these generic over |
@swift-ci Please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
This addresses the need for providing name specifications for
enum
flags, since property wrappers can't be used for enumeration cases.Detailed Design
This includes a new
EnumerableFlag
protocol:As well as new
EnumerableFlag
-constrained@Flag
initializers that replace the current ones that are constrained toString
/CaseIterable
.Documentation Plan
Wrote type- and symbol-level documentation for
EnumerableFlag
, revised docs for the new initializers, and updated the "Argument, Options, and Flags" guide.Test Plan
Modified unit tests to use the new protocol and added tests that use the original, deprecated versions.
Source Impact
This deprecates the
@Flag
initializers that are constrained toCaseIterable
/RawRepresentable
andRawValue == String
. These initializers will continue to work, and can be removed in a future version.Checklist