File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ add_library(ArgumentParser
13
13
"Parsable Properties/Option.swift"
14
14
"Parsable Properties/OptionGroup.swift"
15
15
16
+ "Parsable Types/AsyncParsableCommand.swift"
16
17
"Parsable Types/CommandConfiguration.swift"
17
18
"Parsable Types/EnumerableFlag.swift"
18
19
"Parsable Types/ExpressibleByArgument.swift"
Original file line number Diff line number Diff line change @@ -15,21 +15,34 @@ public protocol AsyncParsableCommand: ParsableCommand {
15
15
}
16
16
17
17
extension AsyncParsableCommand {
18
- public mutating func run( ) throws {
19
- throw CleanExit . helpRequest ( self )
18
+ public static func main( ) async {
19
+ do {
20
+ var command = try parseAsRoot ( )
21
+ if var asyncCommand = command as? AsyncParsableCommand {
22
+ try await asyncCommand. run ( )
23
+ } else {
24
+ try command. run ( )
25
+ }
26
+ } catch {
27
+ exit ( withError: error)
28
+ }
20
29
}
21
30
}
22
31
23
- public protocol AsyncMain {
32
+ @available (
33
+ swift, deprecated: 5.6 ,
34
+ message: " Use @main directly on your root `AsyncParsableCommand` type. " )
35
+ public protocol AsyncMainProtocol {
24
36
associatedtype Command : ParsableCommand
25
37
}
26
38
27
- extension AsyncMain {
39
+ @available ( swift, deprecated: 5.6 )
40
+ extension AsyncMainProtocol {
28
41
public static func main( ) async {
29
42
do {
30
43
var command = try Command . parseAsRoot ( )
31
- if var command = command as? AsyncParsableCommand {
32
- try await command . run ( )
44
+ if var asyncCommand = command as? AsyncParsableCommand {
45
+ try await asyncCommand . run ( )
33
46
} else {
34
47
try command. run ( )
35
48
}
@@ -38,3 +51,4 @@ extension AsyncMain {
38
51
}
39
52
}
40
53
}
54
+
Original file line number Diff line number Diff line change @@ -100,6 +100,10 @@ struct ChangelogAuthors: AsyncParsableCommand {
100
100
}
101
101
}
102
102
103
- @main enum Main : AsyncMain {
104
- typealias Command = ChangelogAuthors
105
- }
103
+ #if swift(>=5.6)
104
+ @main extension ChangelogAuthors { }
105
+ #else
106
+ @main struct AsyncMain : AsyncMainProtocol {
107
+ typealias Command = ChangelogAuthors
108
+ }
109
+ #endif
You can’t perform that action at this time.
0 commit comments