apple / apple/swift-argument-parser
Add completion for default subcommand to supercommand
- Dominant language
- Swift
- Stars
- 3.8k
- Forks
- 411
- Avg merge
- 7d 13h
- Merged PRs (30d)
- 17
Description
As it currently stands, although a command can designate its default subcommand and argument parsing works correctly, there is no completion for arguments, options, or flags of the subcommand unless the subcommand name is specified — which eliminates much of the convenience of having a default subcommand. I'd like it if the completion for the default subcommand was added to the list of all subcommands as the completion for the super command.
Here's an example[^1]:
```swift
@main
struct Greeter: ParsableCommand {
static let configuration = CommandConfiguration(subcommands: [Informal.self, Formal.self], defaultSubcommand: Informal.self)
struct Informal: ParsableCommand {
@Option var firstName: String
func run() throws {
print("Hi, \(firstName)")
}
}
struct Formal: ParsableCommand {
@Option var fullName: String
func run() throws {
print("Good day, \(fullName)")
}
}
}
```
Here's what happens if you run it:
```
$ greeter informal --f # successfully completes to the below line
$ greeter informal --firstName
$ greeter formal --f # successfully completes to the below line
$ greeter formal --fullName
# here's the problem
$ greeter # lists the following completions
--help -h formal help informal
$ greeter --f # no completions
```
Instead, I would like `greeter ` to list all subcommands (as it currently does) _and_ all the completions for its default command, so:
```
$ greeter
--first-name --help -h formal help informal
```
For backwards compatibility and user configurability, it might make sense to make this an optional parameter to the `@Argument`/`@Option`/`@Flag` initializer (or perhaps `CompletionKind`?)
[^1]: I made up this code sample because the project I was working on when I found this error is more complex, but this should get the point across
Contributor guide
Research direction
Start by reproducing the Greeter example and tracing completion handling for a command with defaultSubcommand. Read the existing behavior around CompletionKind and the @Argument/@Option/@Flag initializers. Done means the supercommand offers both its subcommands and the default subcommand's argument, option, and flag completions while preserving configurable backward-compatible behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100