-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow access to previous args in completion function for context-sensitive completions #5784
Comments
Huh, I thought we had an issue for this but can't find one. Passing in an |
Yes |
|
Ah of course. What can I do to help with this? I don't have a ton of time to dedicate to it but I'd like to help if possible. |
This is one of the lower priority tasks as we are focusing on
As such, I'm not going to be setting aside the time to help drive the design of this forward for this to be resolved atm. Previously, I said that #5784 might be initial step but I just realized that there is some extra complexity to that that I had overlooked. |
Please complete the following tasks
Clap Version
clap 4.4.2, clap_complete 4.5.29
Describe your use case
In a ArgValueCompleter function, it would be nice to have access to what has been parsed so far when generating completions. My use case is that I'm loading the arguments from a YAML file, but the file to load from can be overridden by a prior
-f
argument. Another identical example is docker-compose run: You can rundocker-compose run <service>
in which case it will load services fromdocker-compose.yml
, or you can dodocker-compose -f different/compose/file.yml run <service>
, in which case it should load fromdifferent/compose/file.yml
.Describe the solution you'd like
Access to what has already been parsed as an argument to the
ArgValueCompleter
function. This would most likely be a breaking change because it requires adding an argument to ValueCompleter::complete. The user impact could be mitigated though by keeping the blanket impl onfn(&OsStr) -> Vec<CompletionCandidate>
. I imagine most users are not implementingValueCompleter
themselves.The best I can think of is the additional argument is just a
&[&OsStr]
containing what's already been parsed. The completer would then be responsible for iterating over that and figuring out the semantic meaning. It'd be great if we could get the prior arguments in a more structured form, but doing that without the full command present is probably not possible. So an example completion function for something likedocker-compose run
would look like:(this is pseudocode, I'm sure it doesn't actually compile but it should get the idea across)
Alternatives, if applicable
std::env::args
and look for-f
or--file
. This requires you to manually skip over the first few items to get to where the arguments start, which is fragileCommand
struct to parsestd::env::args
, but this requires everything already present to constitute a valid command, i.e. it can't be used to complete a required argument (unless at least one character has already been typed)Additional Context
The text was updated successfully, but these errors were encountered: