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

Delegate completions for a specific argument to the completions of an external program #5424

Open
2 tasks done
alerque opened this issue Mar 25, 2024 · 3 comments
Open
2 tasks done
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@alerque
Copy link
Contributor

alerque commented Mar 25, 2024

Please complete the following tasks

Clap Version

4.5

Describe your use case

I have an app that has several subcommands, some of which are wrappers around other CLI tools. For example casile has several subcommands, but one of them is casile make that sets up a special environment and this passes all the remaining args to make. I have it setup something like this:

#[derive(Subcommand)]
pub enum Commands {
    Make {
        target: Vec<String>,
    },
}

The Vec<String> seems to be the best way to collect further arguments and pass them through to the subprocess. Since passing other flags to make is valid here the arguments beyond this point may or may not be filenames, and even if they are they may or may not exist yet which makes filename completion (as I would get if I made this a Vec<PathBuf> or similar not very useful.

Describe the solution you'd like

I'd like to be able to specify something in the CLI that specifically called out the command for which to use completions for:

#[derive(Subcommand)]
pub enum Commands {
    Make {
        #[clap_complete(delegate="make")]
        target: Vec<String>,
    },
}

I don't know what the exact ergonomics should be, but somehow I'd like the final generated completion scripts to delegate completions for arguments in this position to the completion script of a different external command.

Alternatives, if applicable

No response

Additional Context

I'm not sure all supported shells have a way to handle this, but at least bash and zsh do.

@alerque alerque added the C-enhancement Category: Raise on the bar on expectations label Mar 25, 2024
@epage epage added the A-completion Area: completion generator label Mar 25, 2024
@epage
Copy link
Member

epage commented Mar 25, 2024

This is blocked on #1232

@epage epage added S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 25, 2024
@alerque
Copy link
Contributor Author

alerque commented Mar 25, 2024

I looked at that issue before opening this, but don't think it's related. Implementing this does not require dynamic completion support. Delegating to the completions of another command is not at all the same thing as using the output of a command as completions, and the plumbing needed to make shells do this is different (and simpler).

@epage
Copy link
Member

epage commented Mar 25, 2024

We plan to completely change our completion system, see #3166.

Doing major re-work of our existing completions to fit this is a bit of a dead end and could put us in a design bind for when we get to the end state of #3166.

#3166 is also responsible for us tracking being able to add more dynamic completion state to arguments, like your proposed delegate attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

2 participants