Commit graph

4379 commits

Author SHA1 Message Date
bors[bot]
c8acf5debd
Merge #2976
2976: fix: Loosen reflection lifetimes r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-11-01 21:41:34 +00:00
Ed Page
ade6028da1 fix: Loosen reflection lifetimes
Though we store a lot of values as `&'help str`, we return them as
`&'self str`, making it so they can not be used programmatically as part
of a `App::mut_arg` call.

This loosens the lifetimes so they can be used with `App::mut_arg`.
This also includes a test simulating the desired workflow described in #2966

I skipped `get_all_aliases`.  I ran into problems with lifetimes with
`all_subcommand_names`  and didn't quickly resolve it.  Rather than hold
this up, I punted on it for now.

We'll have to tighten these back up with #1041 but that will also enable
turning them into owned strings, so this will still be possible after
that issue is resolved, just the calls will be slightly different.
2021-11-01 16:28:43 -05:00
bors[bot]
0adfb0fd76
Merge #2979
2979: fix(fig): Reduce deepdencies r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-11-01 20:06:53 +00:00
Ed Page
416b38c43e fix(fig): Reduce deepdencies
Like with #2903, we are depending on more features than needed, forcing
them onto users.  This also impacts our testing since we aren't truly
getting minimal test runs (see #2976).
2021-11-01 14:50:36 -05:00
Ed Page
66341b3c11 fix: Always respect positional occurrences
When supporting multiple occurrences for positional arguments in #2804,
I added some tests to cover this but apparently simpler cases fail
despite those more complicated cases being tested.

This adds more multiple-occurrences tests for positional arguments,
fixes them, and in general equates multiple values with occurrences for
positional arguments as part of #2692.  There are a couple more points
for consideration for #2692 for us to decide on once this unblocks them
(usage special case in #2977 and how subcommand help should be handled).

I fully admit I have not fully quantified the impact of all of these
changes and am heavily relying on the quality of our tests to carry this
forward.
2021-11-01 14:14:04 -05:00
Ed Page
dd2c4c6346 fix(usage)!: Switch positionals... from multi-val to mulit-occur
I noticed this while investigating #2692.  Since we are making
multiple-occurrences a thing for positional arguments, this allows us to
remove a special case.

Another way to look at this is that we should make the default whatever
we do for dervies (#1772).  I'm going to propose we make the derive
always turn `Vec<i32>` into multiple occurences and not multiple values
(with users being able to change it through attributes), but that is an
in-work proposal and not decided yet.

BREAKING CHANGE: `Arg::from(...)` will now use `multiple_occurrences`
for a positional `...`, rather than `multiple_values`.
2021-11-01 12:15:00 -05:00
bors[bot]
96e7dfeb43
Merge #2969
2969: refactor: Allow partially used genned code r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-31 10:32:32 +00:00
bors[bot]
0fe384101f
Merge #2974
2974: fix(usage)!: Separate mutli-occ from multi-val syntax r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-30 19:47:32 +00:00
bors[bot]
dfa4690c96
Merge #2972 #2973
2972: refactor: Remove unused variable r=pksunkara a=epage



2973: test(usage): Make cases more consistent r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-30 18:05:11 +00:00
Ed Page
53bd42a809 fix(usage)!: Separate mutli-occ from multi-val syntax
In looking at multiple occurrences and values for issues like #2692, I
noticed that `...` can mean both multiple values and multiple
occurrences, like before we split them.

Pros
- No syntax change with clap3

Cons
- All the reasons we split `multiple` into two

Uncertain
- I originally started this as part of another branch but I lost track
  if something depended on this.  I'll have to do more digging

BREAKING CHANGE: If `--opt [val]...` was meant for
- only multiple occurrences, see `[opt]... --opt [val]`
- both multiple occurrences and values, see `[opt]... --opt [val]...`
2021-10-30 12:56:49 -05:00
Ed Page
92df0ba263 test(usage): Make cases more consistent
Besides being more explicit / clear, this makes it easier to experiment
with tweaking the logic and keeping the test updates minimal, so the
change of behavior stands out more.
2021-10-30 12:11:49 -05:00
bors[bot]
0e674bcb48
Merge #2968 #2971
2968: test(derive): Provide better error info r=pksunkara a=epage



2971: Fix grammar in doc comment r=epage a=QuantumCoded



Co-authored-by: Ed Page <eopage@gmail.com>
Co-authored-by: Jeffrey <QuantumCoded@users.noreply.github.com>
2021-10-30 16:53:07 +00:00
Ed Page
7661f1f50d refactor: Remove unused variable 2021-10-30 11:46:39 -05:00
bors[bot]
605aa05af8
Merge #2970
2970: chore(error): Remove unused backtrace warning r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-30 15:45:27 +00:00
Jeffrey
d6c2ab4891
Fix grammar in doc comment
Added space after period in doc comment for `subcommand_name`
2021-10-30 10:37:14 -05:00
Ed Page
391980286e refactor: Allow partially used genned code
Wow, I'm having a hard time summarizing this for the summary.

When we code-gen Settings using `impl_settings`, we have no control over
whether one instance of a Settings will use some or all functions.  I
have a fix that removes the one `ArgSettings::unset`, causing warnings
for `ArgSettings` despite needing it for `AppSettings`.

So I'm making it less dependent on how each instantiation uses it.
2021-10-30 10:29:39 -05:00
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
Ed Page
ca29e4760c chore(error): Remove unused backtrace warning
Technically, this also fixes a bug with an extra newline when building
with `debug` but that is a pretty minor cosmetic issue.  It is unclear
if `backtrace` has a trailing newline or not, so I left that as-is.
2021-10-30 09:26:37 -05:00
bors[bot]
b42e2baf59
Merge #2967
2967: fix(derive): Support WaitOnError for derive-genned errors r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-30 14:20:27 +00:00
Ed Page
21cc39678b fix(derive): Support WaitOnError for derive-genned errors
Before, `Error::exit` didn't provide `WaitOnError`, requiring each call
site to duplicate half of `Error::exit`s behavior to get it.  This
hadn't been done for errors raised by derive-generated code.  Ideally,
these errors never happen but all the same, having this consistent would
be good.

This moves knowledge of `WaitOnError` to `Error` (including through
`Error::format`) so `Error::exit` can wait.  Now all of the callers to
`.exit` get a consistent experience without duplication.

While #2938 made a lot of `Error` fields optional for less churn-heavy
modifications, I made this new field required to minimize the risk of an
raise site forgetting to set it.
2021-10-30 09:08:11 -05:00
bors[bot]
5132bbb031
Merge #2966
2966: Add new `App::mut_args` for mutating all arguments r=pksunkara a=repi



Co-authored-by: Johan Andersson <repi@repi.se>
Co-authored-by: Johan Andersson <johan@embark-studios.com>
2021-10-30 12:50:50 +00:00
Johan Andersson
477f884af1 Fix test to support env feature disabled 2021-10-30 14:28:52 +02:00
Johan Andersson
1c73c46af9 Add partial_mut_args test 2021-10-30 13:37:34 +02:00
Johan Andersson
3a9d40fcb8 Add no_auto_version_mut_args test 2021-10-30 13:01:13 +02:00
Johan Andersson
0dded91541
Fix docs variable name
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-30 12:55:46 +02:00
Johan Andersson
6e4ac4cffc Add App::mut_args 2021-10-30 12:26:15 +02: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
Ed Page
4835c00419 fix: Ease transition for now-default settings
We prefer Settings to always be off by default, so when we change a
default, we have to rename.

This adds back in the now-default settings with deprecation messages to
help the user know how things now work.

Unfortunately, there is no way to notify the user that the default they
relied on has changed.  This also doesn't help us when the change in
behavior is more than just an inverting, like `InvalidUtf8` or when a
setting mapped to multiple bits.
2021-10-27 13:07:06 -05:00
Ed Page
99058014d8 fix: Allow using deprecated color AppSettings
This partiall reverts commit efeb02cd34,
bringing back the `AppSettins::Color*` and making them the backing store
for `App::color`, to help ease the transition from clap2->3.

Once we remove these deprecated settings, we might want to keep this
backing store to save on memory.

This is a part of #2617
2021-10-27 13:07:06 -05:00
Ed Page
88b89317ab fix: Ease clap2->3 transition with renamed Settings
This brings back the old name of settings, just deprecated.  Since they
all map to the same bits in the bit field, this should work for
`setting` and `is_set`.  The only thing this lacks is being able to do
equality across variants, whcih seems like a minority case.

Removed settings have some extra care abouts that we'll need to look
into separately.

This is a part of #2617
2021-10-27 13:07:06 -05: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