-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected “Asynchronous subcommand of a synchronous root” #536
Comments
Adding |
@fboundp Thanks for the report and your research into this! I think the best resolution here is to add the workaround as a suggestion in the error message. |
I've tried reproducing this issue, but it seems to be working correctly here.
import ArgumentParser
@main
struct Root: AsyncParsableCommand {
static var configuration = CommandConfiguration(subcommands: [Sub.self])
struct Sub: AsyncParsableCommand {
mutating func run() async throws {
print("Hello World")
}
}
} I've tried reproducing it from both |
I'm experiencing this issue using main, and with the annotation added.
|
#547 should improve the error message when this happens, so that at least it's describing the problem accurately. @timwredwards Can you provide some more detail on your project and what you're seeing? |
Not sure if I'm seeing this same thing or something related, but I just went through a migration from
Then it seemed that no matter what I did I couldn't resolve this error. I tried adding the annotation to my struct as follows: @available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
struct ExampleCLI: AsyncParsableCommand {} and I tried setting let package: Package = Package(
name: "example",
platforms: [
.macOS(.v13),
.macCatalyst(.v13),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
]
} ...and still no dice. Then I found this issue and noticed that some folks were having success with the // CLI Entrypoint
@main
struct CLI {
static var stdin: String?
static func main() {
// check for STDIN before parsing arguments
// usage:
// if let stdin: String = CLI.stdin {
// print("stdin: \(stdin)")
// }
self.stdin = standardInput()
ExampleCLI.main()
}
} As soon as I set the I hope this helps! 😊 PS: I'm doing this whole root command wrapper struct as a dance around capturing standard input and stripping trailing // FeatherDB CLI STDIN Helper
func standardInput() -> String? {
// Only read STDIN if the last argument is "-"
guard CommandLine.arguments.last == "-" else {
return nil
}
// Remove the trailing "-" argument to avoid tripping up ArgumentParser
CommandLine.arguments.removeLast()
// Read & return STDIN
var input: String = String()
while let line: String = readLine() {
input += line
}
return input
} |
@natecook1000 👋 thanks for your work on ArgumentParser! Coming from a background in developing golang CLI tools – which has a robust ecosystem of stdlib & OSS libraries for CLI argument parsing – I've found it to be quite impressive. It has almost everything I could ask for! Any suggestions RE: the behavior I described above? Should I open a separate issue for what I'm seeing, or do you think the behavior I observed is related to this issue? Thanks in advance for your time! 😊 |
I created a related & simple reproducible case here: #688 |
When attempting to create an application with a AsyncParsableCommand root and AsyncParsableCommand subcommands, a fatal error is thrown at runtime “Asynchronous subcommand of a synchronous root.”
ArgumentParser version:
1.2.0
Swift version:
swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50) Target: arm64-apple-macosx13.0
Checklist
main
branch of this packageSteps to Reproduce
source:
Expected behavior
When resulting command is run, help with a subcommand would be displayed.
Actual behavior
The text was updated successfully, but these errors were encountered: