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

bash completion for argument defined with value_name should complete with file names #1179

Closed
Tracked by #1037
jzinn opened this issue Feb 13, 2018 · 4 comments
Closed
Tracked by #1037
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies

Comments

@jzinn
Copy link

jzinn commented Feb 13, 2018

Ripgrep has a -g option that could use some improved Bash completion. Please see

Rust Version

$ rustc -V
rustc 1.25.0-nightly (b8398d947 2018-02-11)

Affected Version of clap

$ grep clap ripgrep/Cargo.lock
name = "clap"
 "clap 2.29.4 (registry+https://github.com/rust-lang/crates.io-index)",
"checksum clap 2.29.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b8f59bcebcfe4269b09f71dab0da15b355c75916a8f975d3876ce81561893ee"

Expected Behavior Summary

Either do nothing:

touch Foo.txt
rg -g Fo<tab>  # hit <tab> to initiate completion
rg -g Fo       # after completion

or complete with file names:

touch Foo.txt
rg -g Fo<tab>  # hit <tab> to initiate completion
rg -g Foo.txt  # after completion

Additionally, the Ripgrep -g option allows a leading ! to indicate negation. If Clap can support this, then an example would be

mkdir vendor
rg -g "!vend<tab>  # hit <tab> to initiate completion
rg -g "!vendor"/   # after completion

Actual Behavior Summary

Currently the typed in value is erased and replaced with <GLOB>...:

touch Foo.txt
rg -g Fo<tab>    # hit <tab> to initiate completion
rg -g <GLOB>...  # after completion

Steps to Reproduce the issue

See above.

Sample Code or Link to Sample Code

I could easily be wrong, but Ripgrep seems to instantiate a clap-rs Arg using something similar to:

Arg::with_name("glob")
    .long("glob")
    .value_name("GLOB")
    .takes_value(true)
    .number_of_values(1)
    .short("g")
    .help("Include or exclude files.")
    .long_help("Include or exclude files and ...")
    .multiple(true)
    .allow_hyphen_values(true)
    ;

It seems that value_name is used in the completion (<GLOB>...) instead of file names.

Debug output

@kbknapp kbknapp added C-bug Category: Updating dependencies P2: need to have A-completion Area: completion generator labels Feb 13, 2018
@kbknapp
Copy link
Member

kbknapp commented Feb 13, 2018

Thanks! I'll take a look at this tomorrow and see if I can get a patch in to just fall back to file completion in all cases.

@jzinn
Copy link
Author

jzinn commented Feb 13, 2018

As an aside, with the current behavior it seems that these options

.takes_value(true)
.number_of_values(1)
.multiple(true)

should not result in <GLOB>..., because the ... indicates that repetition is possible. However, repetition is not allowed in this case because of the call number_of_values(1).

@BurntSushi
Copy link
Contributor

@jzinn That refers to the number of values per use of the flag, and not the number of times the flag can be used. That is, they are orthogonal options. :)

This was referenced Feb 13, 2018
@kbknapp
Copy link
Member

kbknapp commented Feb 13, 2018

v2.30.0 is published

@kbknapp kbknapp mentioned this issue Feb 13, 2018
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-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

3 participants