@@ -25,6 +25,34 @@ public protocol AsyncParsableCommand: ParsableCommand {
2525
2626@available ( macOS 10 . 15 , macCatalyst 13 , iOS 13 , tvOS 13 , watchOS 6 , * )
2727extension AsyncParsableCommand {
28+ /// Parses a new instance of this type from command-line arguments.
29+ ///
30+ /// - Parameter arguments: An array of arguments to use for parsing. If
31+ /// `arguments` is `nil`, this uses the program's command-line arguments.
32+ /// - Returns: A new instance of this type.
33+ /// - Throws: If parsing failed or arguments contains a help request.
34+ public static func parse(
35+ _ arguments: [ String ] ? = nil
36+ ) async throws -> Self {
37+ try parse ( try await parseAsRoot ( arguments) )
38+ }
39+
40+ /// Parses an instance of this type, or one of its subcommands, from
41+ /// command-line arguments.
42+ ///
43+ /// - Parameter arguments: An array of arguments to use for parsing. If
44+ /// `arguments` is `nil`, this uses the program's command-line arguments.
45+ /// - Returns: A new instance of this type, one of its subcommands, or a
46+ /// command type internal to the `ArgumentParser` library.
47+ /// - Throws: If parsing fails.
48+ public static func parseAsRoot(
49+ _ arguments: [ String ] ? = nil
50+ ) async throws -> ParsableCommand {
51+ var parser = CommandParser ( self )
52+ let arguments = arguments ?? Array ( CommandLine . _staticArguments. dropFirst ( ) )
53+ return try await parser. parse ( arguments: arguments)
54+ }
55+
2856 /// Executes this command, or one of its subcommands, with the given arguments.
2957 ///
3058 /// This method parses an instance of this type, one of its subcommands, or
@@ -36,7 +64,7 @@ extension AsyncParsableCommand {
3664 /// `arguments` is `nil`, this uses the program's command-line arguments.
3765 public static func main( _ arguments: [ String ] ? ) async {
3866 do {
39- var command = try parseAsRoot ( arguments)
67+ var command = try await parseAsRoot ( arguments)
4068 if var asyncCommand = command as? AsyncParsableCommand {
4169 try await asyncCommand. run ( )
4270 } else {
0 commit comments