-
Notifications
You must be signed in to change notification settings - Fork 330
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
Deprecate Option initializer and add a new one with parameters in order #391
Deprecate Option initializer and add a new one with parameters in order #391
Conversation
public init( | ||
wrappedValue: Value, | ||
name: NameSpecification = .long, | ||
parsing parsingStrategy: SingleValueParsingStrategy = .next, | ||
completion: CompletionKind? = nil, |
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.
This change isn't ABI stable if I recall correctly, but im not sure if that matters for this library. I wonder if you could leave types as Optional with a default of nil
and use @_disfavoredOverload
to prefer using your new initializer.
@natecook1000 to comment on if this is necessary
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.
I didn't know about @_disfavoredOverload
. Indeed, it seems to do the trick (when re-establishing optionals).
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.
We don't need to worry about ABI stability, since this isn't shipping as a binary library, but for source stability we need the parameter types to stay the same. The default values can go, however, which should be enough to prevent ambiguity between this deprecated version and the new one.
/// - wrappedValue: A default value to use for this property, provided implicitly by the compiler during property wrapper initialization. | ||
/// - name: A specification for what names are allowed for this flag. | ||
/// - parsingStrategy: The behavior to use when looking for this option's value. | ||
/// - help: Information about how to use this option. |
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.
Could you add a description of the completion
parameter?
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.
Sure!
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.
Fixed. I noticed that a lot of completionKind
parameters from other initializers are not documented. What should we do about those ?
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.
Probably worth doing in a separate pull request (if you're up to it)
dc75893
to
e518d1f
Compare
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.
Thanks so much for taking care of this, @McNight! 🎉
In addition to the couple of notes below, could you also add a test that uses the deprecated version of the @Option
initializer? It could go in DefaultsEndToEndTests.swift
.
public init( | ||
wrappedValue: Value, | ||
name: NameSpecification = .long, | ||
parsing parsingStrategy: SingleValueParsingStrategy = .next, | ||
completion: CompletionKind? = nil, |
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.
We don't need to worry about ABI stability, since this isn't shipping as a binary library, but for source stability we need the parameter types to stay the same. The default values can go, however, which should be enough to prevent ambiguity between this deprecated version and the new one.
completion: CompletionKind, | ||
help: ArgumentHelp |
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.
completion: CompletionKind, | |
help: ArgumentHelp | |
completion: CompletionKind?, | |
help: ArgumentHelp? |
@@ -138,12 +138,41 @@ extension Option where Value: ExpressibleByArgument { | |||
/// - name: A specification for what names are allowed for this flag. | |||
/// - parsingStrategy: The behavior to use when looking for this option's value. | |||
/// - help: Information about how to use this option. | |||
@available(*, deprecated, message: "Use init(wrappedValue:name:parsing:help:completion:) instead.") |
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.
Let's be really specific here, since only people who specify both help
and completion
will see this message. Does this read well to you?
@available(*, deprecated, message: "Use init(wrappedValue:name:parsing:help:completion:) instead.") | |
@available(*, deprecated, message: "Swap the order of your 'help' and 'completion' arguments.") |
Also, I usually remove all but the first line of documentation when deprecating something, just to make it appear less valuable.
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.
That's great (I sometimes lack of inspiration when writing documentation or deprecation messages 😅)
e518d1f
to
11f65d8
Compare
I added a test. Please feel free to criticize it. Also:
|
I think you can silence the warning by making the test deprecated and moving the command definition into the test function. |
Yep! If you mark the struct and test as deprecated it should eliminate the warnings. Otherwise this looks ready! 👍🏻 |
11f65d8
to
870285f
Compare
Both work fine; I just marked the struct and test as deprecated because I think it reads better, if that's ok for you @rauhul :) |
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.
Looks great! 🎉
@swift-ci Please test |
This PR marks an
Option
initializer as deprecated because it had its last 2 parameters inverted (help should be before completion, following order of all other initializers).It also adds a new one with parameters in correct order.
It follows recommendations of @natecook1000 in issue #381.
Checklist