Skip to content

Conversation

@nspin
Copy link
Contributor

@nspin nspin commented Nov 13, 2025

Add value_hint for the global --config argument to allow completing its value.

The related #16245 (comment) adds partial support to src/etc/cargo.bashcomp.sh.

What does this PR try to resolve?

Currently, native-completions supports completing the --config flag itself, but not its argument value. This PR adds support for completing its value with a file path (clap::ValueHint::FilePath).

How to test and review this PR?

In a shell supported by native-completions, run:

source <(CARGO_COMPLETE=bash cargo run)

Then, observe that the following completion behaves as expected. That is, the user is prompted with files paths.

cargo --config <tab>

Add value_hint for the global --config arg to allow completing its
value.

Signed-off-by: Nick Spinale <[email protected]>
@rustbot rustbot added the A-cli Area: Command-line interface, option parsing, etc. label Nov 13, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

.global(true)
.hide(true))
.arg(multi_opt("config", "KEY=VALUE|PATH", "Override a configuration value").global(true))
.arg(multi_opt("config", "KEY=VALUE|PATH", "Override a configuration value").value_hint(clap::ValueHint::FilePath).global(true))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one thing worth discussion. According to the doc:

Note: To maintain consistency with existing .cargo/config.toml probing behavior, it is by design that a path in a config file passed via --config is also relative to two levels up from the config file itself.

So personally would expect people usually put their extra config under .cargo/ or .config/. Not sure if this means that we might want to have custom completer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we filter for these, they'll be shown first but all other dirs will still be shown but after.

Whats more of a problem is that it hides the candidates of hidden files and directories. In that state, they are only shown if there are no visible candidates.

I might want to add an override for this in clap. It would be easy to say "don't hide for this completer" but that will then show everything when likely only a subset is wanted. I could have a separate hide function that takes a predicate to override the default hide behavior.

.global(true)
.hide(true))
.arg(multi_opt("config", "KEY=VALUE|PATH", "Override a configuration value").global(true))
.arg(multi_opt("config", "KEY=VALUE|PATH", "Override a configuration value").value_hint(clap::ValueHint::FilePath).global(true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area: Command-line interface, option parsing, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants