Deprecate Option initializer and add a new one with parameters in order#391
Conversation
| wrappedValue: Value, | ||
| name: NameSpecification = .long, | ||
| parsing parsingStrategy: SingleValueParsingStrategy = .next, | ||
| completion: CompletionKind? = nil, |
There was a problem hiding this comment.
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.
I didn't know about @_disfavoredOverload. Indeed, it seems to do the trick (when re-establishing optionals).
There was a problem hiding this comment.
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.
Could you add a description of the completion parameter?
There was a problem hiding this comment.
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.
Probably worth doing in a separate pull request (if you're up to it)
dc75893 to
e518d1f
Compare
natecook1000
left a comment
There was a problem hiding this comment.
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.
| wrappedValue: Value, | ||
| name: NameSpecification = .long, | ||
| parsing parsingStrategy: SingleValueParsingStrategy = .next, | ||
| completion: CompletionKind? = nil, |
There was a problem hiding this comment.
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.
| completion: CompletionKind, | |
| help: ArgumentHelp | |
| completion: CompletionKind?, | |
| help: ArgumentHelp? |
| /// - 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.
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.
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 :) |
|
@swift-ci Please test |
This PR marks an
Optioninitializer 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