Skip to content
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

Merged

Conversation

McNight
Copy link
Contributor

@McNight McNight commented Jan 17, 2022

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

  • 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

public init(
wrappedValue: Value,
name: NameSpecification = .long,
parsing parsingStrategy: SingleValueParsingStrategy = .next,
completion: CompletionKind? = nil,
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Member

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.
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Contributor Author

@McNight McNight Jan 18, 2022

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 ?

Copy link
Contributor

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)

@McNight McNight force-pushed the mcnight/deprecates_option_inverted_parameters branch from dc75893 to e518d1f Compare January 18, 2022 00:31
Copy link
Member

@natecook1000 natecook1000 left a 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,
Copy link
Member

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.

Comment on lines 146 to 147
completion: CompletionKind,
help: ArgumentHelp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.")
Copy link
Member

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?

Suggested change
@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.

Copy link
Contributor Author

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 😅)

@McNight McNight force-pushed the mcnight/deprecates_option_inverted_parameters branch from e518d1f to 11f65d8 Compare January 19, 2022 22:38
@McNight
Copy link
Contributor Author

McNight commented Jan 19, 2022

I added a test. Please feel free to criticize it. Also:

  • I took inspiration from the testParsing_OptionPropertyInit* tests
  • what do you think of the spot where I put it ?
  • what do you think of the naming ?
  • it obviously generates a warning. is it an issue ?

@rauhul
Copy link
Contributor

rauhul commented Jan 20, 2022

I think you can silence the warning by making the test deprecated and moving the command definition into the test function.

@natecook1000
Copy link
Member

Yep! If you mark the struct and test as deprecated it should eliminate the warnings. Otherwise this looks ready! 👍🏻

@McNight McNight force-pushed the mcnight/deprecates_option_inverted_parameters branch from 11f65d8 to 870285f Compare January 21, 2022 18:51
@McNight
Copy link
Contributor Author

McNight commented Jan 21, 2022

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 :)
(Next PR will be one to harmonize documentation regarding completionKind in initializers)

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🎉

@natecook1000
Copy link
Member

@swift-ci Please test

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.

3 participants