From be764ed3413d1b1c409c18d3d8e0d3b3a49773e1 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Thu, 21 May 2020 10:34:41 -0500 Subject: [PATCH] Remove `Never` return from ParsableCommand.main() This provides support for using the `@main` attribute on the root command type. --- .../Parsable Types/ParsableCommand.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift b/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift index a18784426..116655c7e 100644 --- a/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift +++ b/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift @@ -84,18 +84,24 @@ extension ParsableCommand { } /// Parses an instance of this type, or one of its subcommands, from - /// command-line arguments and calls its `run()` method, exiting cleanly - /// or with a relevant error message. + /// the given arguments and calls its `run()` method, exiting with a + /// relevant error message if necessary. /// /// - Parameter arguments: An array of arguments to use for parsing. If /// `arguments` is `nil`, this uses the program's command-line arguments. - public static func main(_ arguments: [String]? = nil) -> Never { + public static func main(_ arguments: [String]?) { do { let command = try parseAsRoot(arguments) try command.run() - exit() } catch { exit(withError: error) } } + + /// Parses an instance of this type, or one of its subcommands, from + /// command-line arguments and calls its `run()` method, exiting with a + /// relevant error message if necessary. + public static func main() { + self.main(nil) + } }