From 442d722675e756c21c7c921d530ab47362d2c020 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Fri, 14 Feb 2025 07:46:30 -0600 Subject: [PATCH] Simplify configuration check for async root command If the synchronous `main()` is running for an `AsyncParsableCommand` root, something went wrong. Previously, this was only diagnosed when there was an async subcommand; this change expands the failure condition to include standalone async commands. Fixes #662. --- .../Parsable Types/ParsableCommand.swift | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift b/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift index c8eaa5d45..024670aa0 100644 --- a/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift +++ b/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift @@ -146,15 +146,12 @@ extension ParsableCommand { /// - 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]?) { - #if DEBUG if #available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *) { - if let asyncCommand = firstAsyncSubcommand(self) { - if Self() is AsyncParsableCommand { - failAsyncPlatform(rootCommand: self) - } else { - failAsyncHierarchy(rootCommand: self, subCommand: asyncCommand) - } + if Self() is AsyncParsableCommand { + failAsyncPlatform(rootCommand: self) + } else if let asyncCommand = firstAsyncSubcommand(self) { + failAsyncHierarchy(rootCommand: self, subCommand: asyncCommand) } } #endif