Skip to content

Commit 0463e7e

Browse files
committed
Update platforms and simplify example availability
1 parent d664ed7 commit 0463e7e

File tree

4 files changed

+25
-51
lines changed

4 files changed

+25
-51
lines changed

Examples/count-lines/CountLines.swift

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if os(macOS)
13-
1412
import ArgumentParser
1513
import Foundation
1614

15+
@main
1716
struct CountLines: AsyncParsableCommand {
1817
@Argument(
1918
help: "A file to count lines in. If omitted, counts the lines of stdin.",
@@ -57,8 +56,12 @@ extension CountLines {
5756
}
5857

5958
mutating func run() async throws {
59+
guard #available(macOS 12, *) else {
60+
print("This example isn't supported on this platform")
61+
return
62+
}
63+
6064
let countAllLines = prefix == nil
61-
6265
let lineCount = try await fileHandle.bytes.lines.reduce(0) { count, line in
6366
if countAllLines || line.starts(with: prefix!) {
6467
return count + 1
@@ -70,21 +73,3 @@ extension CountLines {
7073
printCount(lineCount)
7174
}
7275
}
73-
74-
#if swift(>=5.6)
75-
@main extension CountLines {}
76-
#else
77-
@main struct AsyncMain: AsyncMainProtocol {
78-
typealias Command = CountLines
79-
}
80-
#endif
81-
82-
#else
83-
84-
@main enum Main {
85-
static func main() {
86-
print("Unsupported on this platform.")
87-
}
88-
}
89-
90-
#endif

Package.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
import PackageDescription
1414

15-
let package = Package(
15+
var package = Package(
1616
name: "swift-argument-parser",
17-
platforms: [.macOS(.v12)],
17+
platforms: [.macOS(.v10_15), .macCatalyst(.v13), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
1818
products: [
1919
.library(
2020
name: "ArgumentParser",
@@ -47,15 +47,6 @@ let package = Package(
4747
name: "repeat",
4848
dependencies: ["ArgumentParser"],
4949
path: "Examples/repeat"),
50-
.executableTarget(
51-
name: "count-lines",
52-
dependencies: ["ArgumentParser"],
53-
path: "Examples/count-lines"),
54-
55-
.executableTarget(
56-
name: "changelog-authors",
57-
dependencies: ["ArgumentParser"],
58-
path: "Tools/changelog-authors"),
5950

6051
.testTarget(
6152
name: "ArgumentParserEndToEndTests",
@@ -75,3 +66,16 @@ let package = Package(
7566
resources: [.copy("CountLinesTest.txt")]),
7667
]
7768
)
69+
70+
#if swift(>=5.6)
71+
package.targets.append(contentsOf: [
72+
.executableTarget(
73+
name: "count-lines",
74+
dependencies: ["ArgumentParser"],
75+
path: "Examples/count-lines"),
76+
.executableTarget(
77+
name: "changelog-authors",
78+
dependencies: ["ArgumentParser"],
79+
path: "Tools/changelog-authors"),
80+
])
81+
#endif

Tests/ArgumentParserExampleTests/CountLinesExampleTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if os(macOS)
12+
#if os(macOS) && swift(>=5.6)
1313

1414
import XCTest
1515
import ArgumentParserTestHelpers
1616

1717
final class CountLinesExampleTests: XCTestCase {
18+
@available(macOS 12, *)
1819
func testCountLines() throws {
1920
let testFile = try XCTUnwrap(Bundle.module.url(forResource: "CountLinesTest", withExtension: "txt"))
2021
try AssertExecuteCommand(command: "count-lines \(testFile.path)", expected: "20")

Tools/changelog-authors/ChangelogAuthors.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Foundation
1616

1717
// MARK: Command
1818

19+
@main
20+
@available(macOS 12.1, *)
1921
struct ChangelogAuthors: AsyncParsableCommand {
2022
static var configuration: CommandConfiguration {
2123
CommandConfiguration(
@@ -101,21 +103,3 @@ struct ChangelogAuthors: AsyncParsableCommand {
101103
print(references(for: authors))
102104
}
103105
}
104-
105-
#if swift(>=5.6)
106-
@main extension ChangelogAuthors {}
107-
#else
108-
@main struct AsyncMain: AsyncMainProtocol {
109-
typealias Command = ChangelogAuthors
110-
}
111-
#endif
112-
113-
#else
114-
115-
@main enum Main {
116-
static func main() {
117-
print("Unsupported on this platform.")
118-
}
119-
}
120-
121-
#endif

0 commit comments

Comments
 (0)