Skip to content

Commit ef76d22

Browse files
authored
Convert deprecations from pre-0.1.0 to unavailable (#177)
1 parent b69c4b4 commit ef76d22

File tree

6 files changed

+68
-58
lines changed

6 files changed

+68
-58
lines changed

Sources/ArgumentParser/Parsable Properties/Flag.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ extension Flag {
334334
}
335335
}
336336

337-
// - MARK: Deprecated CaseIterable/RawValue == String
337+
// - MARK: Unavailable CaseIterable/RawValue == String
338338

339339
extension Flag where Value: CaseIterable, Value: RawRepresentable, Value: Equatable, Value.RawValue == String {
340340
/// Creates a property that gets its value from the presence of a flag,
@@ -346,7 +346,7 @@ extension Flag where Value: CaseIterable, Value: RawRepresentable, Value: Equata
346346
/// `nil`, this flag is required.
347347
/// - exclusivity: The behavior to use when multiple flags are specified.
348348
/// - help: Information about how to use this flag.
349-
@available(*, deprecated, message: "Add 'EnumerableFlag' conformance to your value type.")
349+
@available(*, unavailable, message: "Add 'EnumerableFlag' conformance to your value type and, if needed, specify the 'name' of each case there.")
350350
public init(
351351
name: NameSpecification = .long,
352352
default initial: Value? = nil,
@@ -376,7 +376,7 @@ extension Flag where Value: CaseIterable, Value: RawRepresentable, Value: Equata
376376
extension Flag {
377377
/// Creates a property that gets its value from the presence of a flag,
378378
/// where the allowed flags are defined by a case-iterable type.
379-
@available(*, deprecated, message: "Add 'EnumerableFlag' conformance to your value type.")
379+
@available(*, unavailable, message: "Add 'EnumerableFlag' conformance to your value type and, if needed, specify the 'name' of each case there.")
380380
public init<Element>(
381381
name: NameSpecification = .long,
382382
exclusivity: FlagExclusivity = .exclusive,
@@ -409,7 +409,7 @@ extension Flag {
409409
/// - Parameters:
410410
/// - name: A specification for what names are allowed for this flag.
411411
/// - help: Information about how to use this flag.
412-
@available(*, deprecated, message: "Add 'EnumerableFlag' conformance to your value type.")
412+
@available(*, unavailable, message: "Add 'EnumerableFlag' conformance to your value type and, if needed, specify the 'name' of each case there.")
413413
public init<Element>(
414414
name: NameSpecification = .long,
415415
help: ArgumentHelp? = nil

Tests/ArgumentParserEndToEndTests/FlagsEndToEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fileprivate struct RepeatOK: ParsableArguments {
309309
@Flag(exclusivity: .chooseLast)
310310
var shape: Shape
311311

312-
@Flag(name: .shortAndLong, default: .small, exclusivity: .exclusive)
312+
@Flag(default: .small, exclusivity: .exclusive)
313313
var size: Size
314314
}
315315

Tests/ArgumentParserEndToEndTests/SourceCompatEndToEndTests.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -202,39 +202,3 @@ extension SourceCompatEndToEndTests {
202202
}
203203
}
204204

205-
// MARK: - Deprecated APIs
206-
207-
fileprivate struct DeprecatedFlags: ParsableArguments {
208-
enum One: String, CaseIterable {
209-
case one
210-
}
211-
enum Two: String, CaseIterable {
212-
case two
213-
}
214-
enum Three: String, CaseIterable {
215-
case three
216-
case four
217-
}
218-
219-
@Flag() var single: One
220-
@Flag() var optional: Two?
221-
@Flag() var array: [Three]
222-
@Flag(name: .long) var size: Size?
223-
}
224-
225-
extension SourceCompatEndToEndTests {
226-
func testParsingDeprecatedFlags() throws {
227-
AssertParse(DeprecatedFlags.self, ["--one"]) { options in
228-
XCTAssertEqual(options.single, .one)
229-
XCTAssertNil(options.optional)
230-
XCTAssertTrue(options.array.isEmpty)
231-
}
232-
233-
AssertParse(DeprecatedFlags.self, ["--one", "--two", "--three", "--four", "--three"]) { options in
234-
XCTAssertEqual(options.single, .one)
235-
XCTAssertEqual(options.optional, .two)
236-
XCTAssertEqual(options.array, [.three, .four, .three])
237-
}
238-
}
239-
}
240-

Tests/ArgumentParserUnitTests/ErrorMessageTests.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,31 @@ extension ErrorMessageTests {
135135
}
136136
}
137137

138-
private enum OutputBehaviour: String, CaseIterable { case stats, count, list }
139138
private struct Options: ParsableArguments {
140-
@Flag(name: .shortAndLong, default: .list, help: "Program output")
139+
enum OutputBehaviour: String, EnumerableFlag {
140+
case stats, count, list
141+
142+
static func name(for value: OutputBehaviour) -> NameSpecification {
143+
.shortAndLong
144+
}
145+
}
146+
147+
@Flag(default: .list, help: "Program output")
141148
var behaviour: OutputBehaviour
142149

143150
@Flag(inversion: .prefixedNo, exclusivity: .exclusive) var bool: Bool
144151
}
152+
145153
private struct OptOptions: ParsableArguments {
146-
@Flag(name: .short, help: "Program output")
154+
enum OutputBehaviour: String, EnumerableFlag {
155+
case stats, count, list
156+
157+
static func name(for value: OutputBehaviour) -> NameSpecification {
158+
.short
159+
}
160+
}
161+
162+
@Flag(help: "Program output")
147163
var behaviour: OutputBehaviour?
148164
}
149165

Tests/ArgumentParserUnitTests/HelpGenerationTests.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ extension HelpGenerationTests {
115115
""")
116116
}
117117

118-
enum OptionFlags: String, CaseIterable { case optional, required }
118+
enum OptionFlags: String, EnumerableFlag { case optional, required }
119119
enum Degree {
120120
case bachelor, master, doctor
121121
static func degreeTransform(_ string: String) throws -> Degree {
@@ -179,15 +179,32 @@ extension HelpGenerationTests {
179179
""")
180180
}
181181

182-
enum OutputBehaviour: String, CaseIterable { case stats, count, list }
183182
struct E: ParsableCommand {
184-
@Flag(name: .shortAndLong, help: "Change the program output")
183+
enum OutputBehaviour: String, EnumerableFlag {
184+
case stats, count, list
185+
186+
static func name(for value: OutputBehaviour) -> NameSpecification {
187+
.shortAndLong
188+
}
189+
}
190+
191+
@Flag(help: "Change the program output")
185192
var behaviour: OutputBehaviour
186193
}
194+
187195
struct F: ParsableCommand {
188-
@Flag(name: .short, default: .list, help: "Change the program output")
196+
enum OutputBehaviour: String, EnumerableFlag {
197+
case stats, count, list
198+
199+
static func name(for value: OutputBehaviour) -> NameSpecification {
200+
.short
201+
}
202+
}
203+
204+
@Flag(default: .list, help: "Change the program output")
189205
var behaviour: OutputBehaviour
190206
}
207+
191208
struct G: ParsableCommand {
192209
@Flag(inversion: .prefixedNo, help: "Whether to flag")
193210
var flag: Bool

Tests/ArgumentParserUnitTests/ParsableArgumentsValidationTests.swift

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,35 @@ final class ParsableArgumentsValidationTests: XCTestCase {
323323
}
324324
}
325325

326-
// MARK: CaseIterable enum flag has first letter duplication
327-
fileprivate enum ExampleEnum: String, EnumerableFlag {
328-
case first
329-
case second
330-
case other
331-
case forth
332-
case fith
333-
}
326+
// MARK: EnumerableFlag has first letter duplication
334327

335328
fileprivate struct DuplicatedFirstLettersShortNames: ParsableCommand {
336-
@Flag(name: .short, default: .first)
329+
enum ExampleEnum: String, EnumerableFlag {
330+
case first
331+
case second
332+
case other
333+
case forth
334+
case fith
335+
336+
static func name(for value: ExampleEnum) -> NameSpecification {
337+
.short
338+
}
339+
}
340+
341+
@Flag(default: .first)
337342
var enumFlag: ExampleEnum
338343
}
339344

340345
fileprivate struct DuplicatedFirstLettersLongNames: ParsableCommand {
341-
@Flag(name: .long, default: .first)
346+
enum ExampleEnum: String, EnumerableFlag {
347+
case first
348+
case second
349+
case other
350+
case forth
351+
case fith
352+
}
353+
354+
@Flag(default: .first)
342355
var enumFlag2: ExampleEnum
343356
}
344357

0 commit comments

Comments
 (0)