clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
13.65k stars 1.02k forks source link

Support Base Path for ValueHint::*Path types #5427

Closed Swivelgames closed 3 months ago

Swivelgames commented 3 months ago

Please complete the following tasks

Clap Version

4.4.7

Describe your use case

There are certain parameters that I would like to complete using paths. However, some of that paths aren't relative to the Current Working Directory.

Describe the solution you'd like

It would be great if you could specify a base directory for Path-like completions. In a Utopian world, it would also be great to include an optional max-depth:

pub enum ValueHint {
    // ...
    AnyChildPath(PathBuf, Int),
    FileChildPath(PathBuf, Int),
    DirChildPath(PathBuf, Int),
    ExecutableChildPath(PathBuf, Int),
    // ...
}
let start_path = PathBuf::from("/some/path");
let depth = 1;
let hint = Vault::Hint(start_path, depth);

Alternatives, if applicable

The alternative that I'm exploring right now is rolling my own completion for Path, which isn't ideal.

epage commented 3 months ago

Note that ValueHint is specifically meant to capture native shell completions.

1232 is our issue for allowing the user to provide custom completers which is blocked on #3166.

I'm going to close in favor of #1232 as we likely won't support every case for users. We can observe users and maybe pull some things in that are frequently used but I don't want to speculatively keep this issue as open in case this ends up being one of the cases. After the community has adopted #1232, if there is enough of a case that this pattern is common, we can re-evaluate then.