apple / apple/swift-argument-parser

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

Open
#688 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
3.8k
Forks
411
Avg merge
7d 13h
Merged PRs (30d)
17

Description

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](https://github.com/apple/swift-argument-parser/issues)

### Steps to Reproduce

Open [CommandIssue.zip](https://github.com/user-attachments/files/18222928/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.

Contributor guide

Open the contributing guide

Research direction

Start with the attached CommandIssue.zip and run `swift run Tool` to reproduce the crash. Compare the behavior with and without `SubCommand` in `CommandIssue.configuration`, then trace the `Command.main(CommandLine.arguments)` path for asynchronous root and subcommands. Done means the configured parent and subcommand run without the availability fatal error and print the expected hello world message.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.