Skip to content

Add completion for default subcommand to supercommand #488

Open
@Samasaur1

Description

@Samasaur1

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 example1:

@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<Tab> # successfully completes to the below line
$ greeter informal --firstName

$ greeter formal --f<Tab> # successfully completes to the below line
$ greeter formal --fullName

# here's the problem
$ greeter <Tab> # lists the following completions
--help    -h        formal    help      informal
$ greeter --f<Tab> # no completions

Instead, I would like greeter <Tab> to list all subcommands (as it currently does) and all the completions for its default command, so:

$ greeter <Tab>
--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?)

Footnotes

  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions