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

Shell completion generation fails in loop with global flags/options #846

Closed
Fleshgrinder opened this issue Feb 8, 2017 · 2 comments
Closed
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies
Milestone

Comments

@Fleshgrinder
Copy link

Rust Version

N/A

Affected Version of clap

Probably all but 2.20.3 was the one where the bug was encountered.

Expected Behavior Summary

Build and compilation should succeed.

Actual Behavior Summary

Build fails with the following output:

$ cargo build
   Compiling mwe v0.1.0 (file:///D:/GitHub/rust-phpup)
error: failed to run custom build command for `mwe v0.1.0 (file:///D:/GitHub/rust-phpup)`
process didn't exit successfully: `D:\GitHub\rust-phpup\target\debug\build\mwe-563482c66f20550f\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Non-unique argument name: quiet is already in use', C:\Users\Fleshgrinder\.cargo\registry\src\github.com-1ecc6299db9ec823\clap-2.20.3\src\app\parser.rs:147
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Steps to Reproduce the issue

cargo build the code linked in the Gist

Sample Code or Link to Sample Code

https://gist.github.com/Fleshgrinder/3b562bb6c91deb49635543e68f720651

Reason

The problem occurs due to gen_completion and build.rs where the app is reused in the loop as you discovered already in a short Gitter chat.

@kbknapp
Copy link
Member

kbknapp commented Feb 9, 2017

Thanks, as per our discussion on gitter, I shuold have this fixed soon 😄

@kbknapp
Copy link
Member

kbknapp commented Feb 9, 2017

Also, incase anyone else is running into this calling the gen_completions causes all global Args to be propogated, on second and further iterations of the loop, this causes duplicate Args to be built which is an error.

This is a bug, and those duplicate Args should be ignored in this case.

The temporary fix is to rebuild the App struct with each iteration of the loop (which takes nanoseconds, so isn't a big deal).

for shell in &[Shell::Bash, Shell::PowerShell] {
    let mut app = build_cli();
    app.gen_completions(env!("CARGO_PKG_NAME"), *shell, env!("OUT_DIR"));
}

@kbknapp kbknapp added A-completion Area: completion generator D: easy C-bug Category: Updating dependencies labels Feb 9, 2017
@kbknapp kbknapp added this to the 2.20.4 milestone Feb 9, 2017
kbknapp referenced this issue Feb 9, 2017
…ally propagating global args values down through *used* subcommands

Closes #694
@homu homu closed this as completed in 5e9b9cf Feb 15, 2017
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

2 participants