diff --git a/Sources/ArgumentParser/Parsable Properties/Option.swift b/Sources/ArgumentParser/Parsable Properties/Option.swift index b81d5716..2a8523b8 100644 --- a/Sources/ArgumentParser/Parsable Properties/Option.swift +++ b/Sources/ArgumentParser/Parsable Properties/Option.swift @@ -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, diff --git a/Tests/ArgumentParserEndToEndTests/DefaultsEndToEndTests.swift b/Tests/ArgumentParserEndToEndTests/DefaultsEndToEndTests.swift index dd850252..f9b9fd7d 100644 --- a/Tests/ArgumentParserEndToEndTests/DefaultsEndToEndTests.swift +++ b/Tests/ArgumentParserEndToEndTests/DefaultsEndToEndTests.swift @@ -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") + } + } +}