apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.3k stars 311 forks source link

Fix for `@Option(transform:)` with optional type #619

Closed natecook1000 closed 5 months ago

natecook1000 commented 6 months ago

Due to the restructuring in #477, there was ambiguity between the unconstrained @Option initializer that uses a transform (but no initial value) and the one that is constrained to the property being optional. This marks the unconstrained version as disfavored, which allows overload resolution to select the optional version when appropriate.

Fixes #618.

Checklist

natecook1000 commented 6 months ago

@swift-ci Please test

Coeur commented 6 months ago

Thank you Nate. To be exhaustive, we also need to fix Argument.swift by adding @_disfavoredOverload line 417, and add the same test replacing @Option with @Argument.

natecook1000 commented 6 months ago

@swift-ci Please test

Coeur commented 6 months ago

Question: to facilitate the understanding of the documentation, should we make such below changes too?

Option.swift, Line 508, change:

  /// var foo: String = "bar"

To:

  /// var foo: String? = "bar"

Option.swift, Line 577, change:

  /// var foo: String

To:

  /// var foo: String?
natecook1000 commented 5 months ago

@swift-ci Please test

natecook1000 commented 5 months ago

@swift-ci Please test