-
-
Notifications
You must be signed in to change notification settings - Fork 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
Flag also parsed as positional argument #946
Comments
Thanks for taking the time to file this! I've confirmed the bug, and it should be an easy one to fix. Also, just to note |
Great! Thanks for pointing out that there's a difference between |
They do the same thing, one is globally ( The documentation is out of date (embarrassed). That was true before |
…es when specific combinations of settings were used This commit fixes a bug where using `AppSettings::AllowHyphenValues` would cause flags with longs be *also* parsed as positional values. Closes #946
2.24.1 is on crates.io |
Rust Version
N/A, but tested on latest nightly
Affected Version of clap
2.22.1
Expected Behavior Summary
With a single, optional positional argument and a flag, we don't parse the flag as the positional argument. I also set
AllowLeadingHyphen
, since some of my arguments start with-C
.Actual Behavior Summary
The optional positional argument is parsed as
Some("--verbose")
instead ofNone
, and--verbose
is also parsed.Steps to Reproduce the issue
I'm not really sure what to put here, but basically
app --verbose
is parsed as:is_present("--verbose") = true
Sample Code or Link to Sample Code
https://github.com/Mark-Simulacrum/rust/tree/cleanup is the branch, but you'll need to cd to src/tools/compiletest and then just cargo build should work.
After that, running this command reproduces the issue, pay attention to how filter is printed as
Some("--verbose")
in the debug output:./src/target/debug/compiletest "--compile-lib-path" "./rust/build/x86_64-unknown-linux-gnu/stage1/lib" "--run-lib-path" "./rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "./rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "--rustdoc-path" "./rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustdoc" "--src-base" "./rust/src/test/compile-fail" "--build-base" "./rust/build/x86_64-unknown-linux-gnu/test/compile-fail" "--stage-id" "stage1-x86_64-unknown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "./rust/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O" "--target-rustcflags" "-Crpath -O -Lnative=./rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--llvm-version" "4.0.1\n" "--verbose" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" ""
Debug output
https://gist.github.com/Mark-Simulacrum/b86c4f16f922be7ef542e7853cf93e01, with what I think being relevant here: https://gist.github.com/Mark-Simulacrum/b86c4f16f922be7ef542e7853cf93e01#file-gistfile1-txt-L1590
The text was updated successfully, but these errors were encountered: