Deprecate Option initializer and add a new one with parameters in order (#391)

This commit is contained in:
Adam McNight
2022-01-25 10:43:44 -06:00
committed by GitHub
parent 4cdcc1781d
commit 2b352c08c2
2 changed files with 36 additions and 2 deletions
@@ -126,6 +126,23 @@ extension Option where Value: ExpressibleByArgument {
)
}
/// Creates a property with a default value provided by standard Swift default value syntax.
@available(*, deprecated, message: "Swap the order of your 'help' and 'completion' arguments.")
public init(
wrappedValue: Value,
name: NameSpecification = .long,
parsing parsingStrategy: SingleValueParsingStrategy = .next,
completion: CompletionKind?,
help: ArgumentHelp?
) {
self.init(
name: name,
initial: wrappedValue,
parsingStrategy: parsingStrategy,
help: help,
completion: completion)
}
/// Creates a property with a default value provided by standard Swift default value syntax.
///
/// This method is called to initialize an `Option` with a default value such as:
@@ -138,12 +155,13 @@ 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.
/// - completion: Kind of completion provided to the user for this option.
public init(
wrappedValue: Value,
name: NameSpecification = .long,
parsing parsingStrategy: SingleValueParsingStrategy = .next,
completion: CompletionKind? = nil,
help: ArgumentHelp? = nil
help: ArgumentHelp? = nil,
completion: CompletionKind? = nil
) {
self.init(
name: name,
@@ -777,3 +777,19 @@ extension DefaultsEndToEndTests {
}
}
}
@available(*, deprecated)
fileprivate struct OptionPropertyDeprecatedInit_NoDefault: ParsableArguments {
@Option(completion: .file(), help: "")
var data: String = "test"
}
extension DefaultsEndToEndTests {
/// Tests that instances created using deprecated initializer with completion and help arguments swapped are constructed and parsed correctly.
@available(*, deprecated)
func testParsing_OptionPropertyDeprecatedInit_NoDefault() {
AssertParse(OptionPropertyDeprecatedInit_NoDefault.self, []) { arguments in
XCTAssertEqual(arguments.data, "test")
}
}
}