Skip to content
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

Running Command.main() on an AsyncParseableCommand with AsyncParseableCommand sub commands will crash #688

Open
bolsinga opened this issue Dec 22, 2024 · 1 comment

Comments

@bolsinga
Copy link

bolsinga commented Dec 22, 2024

I have a AsyncParseableCommand with one AsyncParseableCommand sub commands. My package is built targeting macOS 15.

If I run the "parent" Command with Command.main(CommandLine.arguments) it will fail with the message:

ArgumentParser/ParsableCommand.swift:264: Fatal error: 
--------------------------------------------------------------------
Asynchronous root command needs availability annotation.

The asynchronous root command `CommandIssue` needs an availability
annotation in order to be executed asynchronously. To fix this issue,
add the following availability attribute to your `CommandIssue`
declaration or set the minimum platform in your "Package.swift" file.

@available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
--------------------------------------------------------------------

ArgumentParser version: 1.5.0
Swift version: swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1) Target: arm64-apple-macosx15.0

Checklist

  • [x ] If possible, I've reproduced the issue using the main branch of this package
  • [ x] I've searched for existing GitHub issues

Steps to Reproduce

Open CommandIssue.zip

Set up the reproducible directory:
swift run Tool
It will crash with the above.

Remove the SubCommand from the CommandIssue.configuration.
swift run Tool
It will not crash.

Expected behavior

I expect that this will not report that it is not working due to building for an asynchronous command supporting platform, since it is. I expect it to print a hello world message. FWIW I also filed FB16143524.

Actual behavior

It will crash as described above.

@bolsinga
Copy link
Author

I found a workaround. It seems that the main.swift call of CommandIssue.main() calls the ParsableCommand version, not the AsyncParsableCommand version. I could not figure out how to "cast" it. Adding await CommandIssue.main() did not help. So I added static func go(_ arguments: [String]) async, and I call that from the main.swift file.

bolsinga added a commit to bolsinga/itunes_json that referenced this issue Dec 23, 2024
this way the bundled app can call any of the sub commands in the future.

the go() is to workaround apple/swift-argument-parser#688
bolsinga added a commit to bolsinga/itunes_json that referenced this issue Dec 23, 2024
this way the bundled app can call any of the sub commands in the future.

the go() is to workaround
apple/swift-argument-parser#688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant