Commit graph

4251 commits

Author SHA1 Message Date
Ed Page
4b7ed54d7e test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked.  I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.

So let's switch to `Parse::try_parse_from`.

Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context

USAGE:
    clap_derive [OPTIONS]

For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok

failures:

---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
 context", None), ("\n\n", None), ("USAGE:\n    clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    vector

test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 10:00:34 -05:00
bors[bot]
2ce916133b
Merge #2961 #2965
2961: Pin the zola version used to deploy the site r=epage a=pksunkara



2965: fix(error): Never show unrequested color r=pksunkara a=epage



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-29 23:00:12 +00:00
bors[bot]
98c5f78d3b
Merge #2964
2964: test(derive): Verify derive-genned errors are formatted r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-29 21:53:08 +00:00
Ed Page
6126f998d1 fix(error): Never show unrequested color
If the user prints a raw error, it may include color even if the user
turned it off at runtime.  Now we'll be more conservative and never show
color for raw errors.

This is a follow up to #2943; apparently I had missed some cases.
2021-10-29 16:28:23 -05:00
Ed Page
93c26dd420 test(derive): Verify derive-genned errors are formatted
This is to help verify behavior added in #2943.  We separated the error
raising site from the error formatting site and this verifies that the
formatting actually happens.
2021-10-29 16:09:07 -05:00
bors[bot]
7ce5d79de3
Merge #2962
2962: Fix some test cases to print correct failure message r=epage a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-29 17:59:20 +00:00
Pavan Kumar Sunkara
2984748762 Fix some test cases to print correct failure message 2021-10-29 18:48:23 +01:00
Pavan Kumar Sunkara
2ffb49ccff
Pin the zola version used to deploy the site 2021-10-29 17:07:49 +01:00
bors[bot]
b5e390008c
Merge #2957
2957: Allow r_unless_all to be used along with r_unless_any r=ldm0 a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-29 15:45:05 +00:00
bors[bot]
0ad042ac0b
Merge #2959
2959: Update site r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-28 23:06:52 +00:00
Pavan Kumar Sunkara
34ac79f9b0 Update site 2021-10-28 21:08:22 +01:00
Pavan Kumar Sunkara
92977060be
Allow r_unless_all to be used along with r_unless_any 2021-10-28 00:10:30 +01:00
bors[bot]
0d7a0a81c2
Merge #2950
2950: Fix default value behaviour with conflicts and requirement validation r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-27 20:16:21 +00:00
bors[bot]
281eba244d
Merge #2000
2000: Make methods from ArgMatches panic on unknown argument r=pksunkara a=CreepySkeleton



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-27 09:23:04 +00:00
Pavan Kumar Sunkara
0cbec63489 Make sure that ArgMatches methods panic on unknown arg, not return false 2021-10-27 02:42:30 +01:00
bors[bot]
a802662341
Merge #2952 #2953
2952: fix(derive): Don't duplicate subcommand aliases r=pksunkara a=epage



2953: docs(app): Correlate help_heading and subcommand_placeholder r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-26 21:56:54 +00:00
Pavan Kumar Sunkara
ac1de1fc78
Fixes arg having required_unless on default values 2021-10-26 22:27:10 +01:00
Ed Page
f3fec3ed0f docs(app): Correlate help_heading and subcommand_placeholder
This is to increase the chance a user discovers what they are looking
for, by using similar terms and cross-linking.
2021-10-26 16:21:02 -05:00
Pavan Kumar Sunkara
a88562c12b
Fixes arg having required_if on default values 2021-10-26 22:18:01 +01:00
Pavan Kumar Sunkara
130dcbfdd9
Fixes arg and group with default value having requires 2021-10-26 22:18:01 +01:00
Pavan Kumar Sunkara
c4fdb1dd42
Improve requirements validation by removing dead code 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
01869744c2
Fixes group conflicting if two args with default values 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
64a2866b09
Fixes arg conflicting with group whose arg has default value 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
8c76556ac4
Fixes group conflicting with arg which has default value 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
261a2c00e8
Added ArgMatcher::is_default_value abstraction 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
bf91a1a35a
Improve debug assert for required group and default value interaction 2021-10-26 22:17:59 +01:00
Pavan Kumar Sunkara
b21c15f8b6
Dedupe some tests and improve others 2021-10-26 22:17:59 +01:00
Pavan Kumar Sunkara
4edcda2b99
Revert "docs: Clarify corner caseses with default values"
This reverts commit 45ef0722f3.
2021-10-26 22:17:59 +01:00
Ed Page
d05622d015 fix(derive): Don't duplicate subcommand aliases
When an anonymous struct is inside of an enum, we end up applying the
App methods twice, once for the `augment_args` and once for variant.

This consolidates those calls.

Fixes #2898
2021-10-26 16:01:05 -05:00
bors[bot]
f9e074e554
Merge #2926 #2948
2926: Put `grouped_values_of` behind a feature gate r=pksunkara a=epage



2948: docs(generate): Move derive example to generate r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-26 20:56:20 +00:00
bors[bot]
07fcaa9597
Merge #2943
2943: fix(derive)!: Don't Panic, Error r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-26 19:47:09 +00:00
Ed Page
bfa388420b Put grouped_values_of behind a feature gate
There is enough open work on this, we should probably not have it public
yet, so putting it behind a gate.  See https://github.com/clap-rs/clap/issues/2924
2021-10-26 14:26:50 -05:00
Ed Page
a065702205 docs(generate): Move derive example to generate
From a users perspective, `clap_derive` is baked into `clap`.
`clap_generate is an add on to `clap`.  So it seems best to have all
`clap_generate` examples in `clap_generate` where a user will look for
them.

Fixes #2939
2021-10-26 14:26:50 -05:00
Ed Page
53e10b41e3 fix(derive)!: Error, don't panic!
The derive is generating `Error::raw` (from scratch or by converting
existing erors) and then the inherent `Parser` methods format them.

Fixes #2255
2021-10-26 14:26:50 -05:00
Ed Page
f8bca3a84b fix(error): Never show unrequested color
If the user prints a raw error, it may include color even if the user
turned it off at runtime.  Now we'll be more conservative and never show
color for raw errors.
2021-10-26 14:26:50 -05:00
Ed Page
3c4340c583 feat(error): Allow separate raise, format sites
While `App::error` is what most people will need, `clap_derive` needs to
handle when the site raising the error doesn't have access to the `App`
and needs to defer that to later.
2021-10-26 14:26:50 -05:00
Ed Page
83b074ae92 refactor(error): Extract formatting of raw messages 2021-10-26 14:26:50 -05:00
Ed Page
f1bf9fc250 refactor(error): Delay formatting until the end
This gives us room to add extra context later.
2021-10-26 14:26:50 -05:00
bors[bot]
c0ac536cb7
Merge #2949
2949: fix(derive): Use variants help_heading r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-26 18:07:23 +00:00
Ed Page
69a7b7133a fix(derive): Use variants help_heading
Due to a copy/paste bug, we were reading the `help_heading` for
Subcommands from the enum's attribute and not the variant's attribute.

It doesn't make sense for the outer command's help_heading to control
the subcommands help_heading.

This does raise an interesting question on inheriting / propagating help_heading,
which I originally wrote the tests for.  We'd first need to answer
whether it should be built-in to the builder or derive-specific.
2021-10-26 12:49:43 -05:00
bors[bot]
b77b4e43a6
Merge #2942
2942: fix(derive): Support arg_enum everywhere r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-25 21:53:59 +00:00
Ed Page
5d036d4d34 fix(derive): Support arg_enum everywhere
In working on converting unwraps to errors, I noticed that we did not
spport `arg_enum` for  `Option<Option<_>>` and `Option<Vec<_>>`, so this
addresses that.

My main motivation was to consolidate and make the logic more
consistent, the bug fix just fell out of that work.
2021-10-25 14:12:08 -05:00
bors[bot]
29972e162a
Merge #2896
2896: docs: Clarify corner caseses with default values r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-25 16:48:17 +00:00
bors[bot]
d6462884ed
Merge #2941
2941: Fix a path incompatible with re-exports r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-25 15:40:33 +00:00
Ed Page
345694fea8 fix(derive): Allow subcommands with re-exporting
Our approach to re-exporting is to not fully qualify symbols in `clap`.
This is a place where a leading `::` got introduced, so its being
removed.
2021-10-25 09:44:38 -05:00
Ed Page
92fea91dfe doc(derive): Note derive policies 2021-10-25 09:44:05 -05:00
bors[bot]
c8d7d4fbc8
Merge #2927
2927: test: Verify clap_derive README r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-25 14:33:26 +00:00
Ed Page
ed987933cf test: Verify clap_derive README
Fixes #2920
2021-10-25 09:21:45 -05:00
bors[bot]
5672bf9529
Merge #2930
2930: feat(derive): Allow `help_heading` on flattening fields r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-24 23:21:45 +00:00
bors[bot]
28a043de8d
Merge #2938
2938: refactor(error): Make 'Error' less churn heavy r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-24 21:57:57 +00:00