-
Notifications
You must be signed in to change notification settings - Fork 47
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
[WIP] Switch from structopt to clap v4 #55
Conversation
Hi @lukehsiao, thanks for the contribution. I will review it more closely soon. |
As clap v3 is now out, and the structopt features are integrated into (almost as-is), structopt is now in maintenance mode: no new feature will be added [[1]]. Consequently, it seems appropriate to switch to clap v3 to benefit from the continued development. clap v3 is slightly larger than structopt. This is the affect on some basic metrics: | Metric | Before | After | |-----------------------|--------|-------| | compile release (sec) | 6.25 | 8.00 | | binary size (MB) | 6.2 | 6.3 | Also note that we break away from the default clap v3 behavior in one case: exit codes. In the transition for v2 to v3, clap switched from an exit status of 1 to an exit status of 2. For compatibility with previous version of `choose`, we still return an exit code of 1, rather than 2. [1]: https://docs.rs/structopt/latest/structopt/#maintenance Tested: Ran `cargo test`: test result: ok. 206 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s Ran `test/e2e_test.sh`: All tests passed
All of these are directly suggested changes from running `cargo clippy`. Tested: Ran `cargo test`: test result: ok. 206 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s Ran `test/e2e_test.sh`: All tests passed
Clap just released v4: https://epage.github.io/blog/2022/09/clap4/. I've explored using clap v4, which is smaller than v3 and would be nice to use. But, there is one implementation difference that makes
where the other ordering works:
Looking into see if there is a way to resolve this. This could be a clap bug. So, I suppose this PR should be updated either to clap v4, or, if you want a lighter-weight option, |
Ok, I believe this is a clap v4 bug.
This behavior just doesn't seem to be true for our situation. Perhaps the combination of allow_hyphen_values = true and value_parser = parse::choice breaks this behavior. |
Tracking here: clap-rs/clap#4283 |
I've also confirmed Specifically, it does not have something like |
Thanks for the thorough updates. It looks like if we want to convert to clap (whether v4 or v3) we need to hold off a bit until the negative number parsing we use is possible. Do I have that right? |
Almost. Clap v3 actually works fine (this PR minus the My thought is just ignore this PR until clap v4 supports the usage. Otherwise, if we want clap v4 before they fix (if they decide to fix it, it seems up in the air right now), we'd need to release a new |
Agreed. Let's wait and see if clapv4 can work for us, and if it ends up that it isn't going to work, we can decide how to proceed from there. |
consider this test case - it allows to parse #[test]
fn fancy_negative() {
let a = short('a').req_flag(());
let b = any::<i64>("A");
let ab = construct!(a, b).adjacent().anywhere().map(|x| x.1);
let c = short('c').argument::<usize>("C").fallback(42);
let parser = construct!(c, ab).to_options();
let r = parser.run_inner(Args::from(&["-a", "-10"])).unwrap();
assert_eq!(r, (42, -10));
let r = parser
.run_inner(Args::from(&["-a=-20", "-c", "110"]))
.unwrap();
assert_eq!(r, (110, -20));
let r = parser
.run_inner(Args::from(&["--help"]))
.unwrap_err()
.unwrap_stdout();
let expected = "\
Usage: [-c C] -a <A>
Available options:
-c <C>
-a
-h, --help Prints help information
";
assert_eq!(r, expected);
} Generated help is a bit strange - it contains only let ab = ab.hide();
let a = short('a').help("help message").argument();
let parser = construct!([ab, a]) Resulting The way |
Thanks @pacak! Does this cover just plain positionals, e.g. See a larger set of example args here: Lines 9 to 26 in b9ab074
|
-4:x and -i here are both positional? If so - yes, "any" by itself can
handle them.
…On Sun, Nov 27, 2022, 23:01 Luke Hsiao ***@***.***> wrote:
Thanks @pacak <https://github.com/pacak>!
Does this cover just plain positionals, e.g. -4:-2 -i
${test_dir}/lorem.txt? That is, not just supporting hyphen values, but
hyphen values that do not come after a flag?
See a larger set of example args here:
https://github.com/theryangeary/choose/blob/b9ab07470f2513d9422581de1219ecb8683b513c/test/e2e_test.sh#L9-L26
—
Reply to this email directly, view it on GitHub
<#55 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAQFI54G5G6FNOAK5SD2UDWKQVDBANCNFSM6AAAAAAQVL7W4Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
To parse let shape = any::<String>("SHAPE").parse(xxxx);
let file = short('i').argument::<FileBuf>("FILE");
let parser = construct!(file, shape).to_options(); Plus usual help, etc. where Turbofishes are optional if |
As clap v3 is now out, and the structopt features are integrated into
(almost as-is), structopt is now in maintenance mode: no new feature
will be added [1]. Consequently, it seems appropriate to switch to
clap v3 to benefit from the continued development.
clap v3 is slightly larger than structopt. This is the affect on some
basic metrics:
Also note that we break away from the default clap v3 behavior in one
case: exit codes. In the transition for v2 to v3, clap switched from an
exit status of 1 to an exit status of 2. For compatibility with previous
version of
choose
, we still return an exit code of 1, rather than 2.Tested:
Ran
cargo test
:Ran
test/e2e_test.sh
:In addition, this PR cleans up some clippy lints while we're at it :). You can see these yourself if you checkout after the first commit and run
cargo clippy
with clippy v0.1.64.I'd suggest reviewing patch-by-patch, I tried to organize the changes.