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

Arg dynamic completion via ValueHint::Execute(String) #5449

Closed
2 tasks done
sigoden opened this issue Apr 9, 2024 · 1 comment
Closed
2 tasks done

Arg dynamic completion via ValueHint::Execute(String) #5449

sigoden opened this issue Apr 9, 2024 · 1 comment
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change.

Comments

@sigoden
Copy link

sigoden commented Apr 9, 2024

Please complete the following tasks

Clap Version

master

Describe your use case

Add dynamic completion for clap::Arg

Describe the solution you'd like

Add ValueHint::Execute(String) to generating possible completion candidates by exectuting the command.

Describe the solution you'd like

Add ValueHint::Execute(String) to generate possible completion candidates by executing the command.

Command::new("aichat")
    .arg(
        Arg::new("model")
            .short('m')
            .long("model")
            .value_hint(ValueHint::Execute("aichat --list-models"))
    )


#[derive(Args, Debug, PartialEq)]
struct AichatCli {
    #[arg(long, value_hint = ValueHint::Execute("aichat --list-models"))]
    model: Option<String>,
}
$ aichat -m <tab>
openai:gpt-3.5-turbo
openai:gpt-3.5-turbo-1106
...

Each line of the command output is a possible completion candidate.

Environment variabes $COMP_LINE and $COMP_POINT should passed when executing the command.

Alternatives, if applicable

No response

Additional Context

Similar issues:

Solved issues:

@sigoden sigoden added the C-enhancement Category: Raise on the bar on expectations label Apr 9, 2024
@epage epage added M-breaking-change Meta: Implementing or merging this will introduce a breaking change. A-completion Area: completion generator labels Apr 9, 2024
@epage
Copy link
Member

epage commented Apr 9, 2024

The given use case for this proposal is focused on "let me provide dynamic completions by teaching clap how to call back into myself to provide those completions". This in effect is an alternative to #1232 which the issue acknowledges.

I prefer issues to be organized around problems, rather than solutions. This ensures we have a holistic conversation, rather than spreading the conversation out across multiple issues, making ti hard to follow.

I feel this would be encouraging people to extend their CLIs in ways that don't make sense from a CLI perspective but just as a workaround for not having the proposed solution in #1232.

This proposal also reuses something targeted at integrating in with shell logic but not for shell logic.

This is also a breaking change since ValueHint is Copy. This isn't a reason to say "no" to something on its own but that it raises the bar, making this not viable for a short term solution to a problem.

For these reasons, I'm closing this out. If you have a reason we should reconsider, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
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 M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Projects
None yet
Development

No branches or pull requests

2 participants