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

Add completion for default subcommand to supercommand #488

Open
Samasaur1 opened this issue Sep 10, 2022 · 0 comments
Open

Add completion for default subcommand to supercommand #488

Samasaur1 opened this issue Sep 10, 2022 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Samasaur1
Copy link

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

@natecook1000 natecook1000 added enhancement New feature or request help wanted Extra attention is needed labels Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants