Commit graph

4188 commits

Author SHA1 Message Date
Jake Shadle
db2a25473a Fix packaging of LICENSE-* files 2021-10-21 14:57:49 +02:00
bors[bot]
c4dfb1aede
Merge #2916
2916: fix ArgEnum multiline doc comment r=epage a=marjakm



Co-authored-by: Mattis Marjak <mattis.marjak@gmail.com>
2021-10-19 17:06:14 +00:00
bors[bot]
07ec0440bf
Merge #2908
2908: fix!: Rename ArgValue to PossibleValue r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-19 15:58:56 +00:00
Mattis Marjak
cba7ba5369 fix ArgEnum multiline doc comment 2021-10-19 18:34:54 +03:00
Ed Page
9f12bfec47 fix!: Rename ArgValue to PossibleValue
In considering potential work for #2683, I realized we might need a type to carry data for
each of the `multiple_values`.  `ArgValue` works both for that and for
possible values, so we need to come up with a better name for one or
both.  Changing `ArgValue`s name now would be ideal since its new in
clap3 and by renaming it, we can reduce churn for users.

While thinking about this, I realized I regularly get these mixed
up, so renaming `ArgValue` to `PossibleValue` I think will help clear
things up, regardless of #2683.
2021-10-19 10:10:37 -05:00
bors[bot]
fe29af7a63
Merge #2909
2909: feat(doc): Fix many typos in docs, comments and codes found by typos-cli r=pksunkara a=rhysd



Co-authored-by: rhysd <lin90162@yahoo.co.jp>
2021-10-19 11:28:04 +00:00
rhysd
8a7d217fe6 fix(test): Fix 'unused return value' lint warnings 2021-10-19 16:34:05 +09:00
rhysd
e666763acf feat(doc): Fix positions of indices 2021-10-19 16:30:25 +09:00
rhysd
012f318c97 feat(doc): Fix many typos in docs, comments and codes found by typos-cli 2021-10-19 10:38:22 +09:00
bors[bot]
693fae5090
Merge #2875
2875: Performance "Improvements" r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-18 22:18:38 +00:00
Ed Page
e2865c91be perf: Reduce allocations on 'args'
This seems like it'd have close to the same benefits as the suggestion
in the TODO, resolving it.
2021-10-18 16:14:31 -05:00
Ed Page
294cabf7c6 perf: Don't allocate a throw-away Vec 2021-10-18 16:14:31 -05:00
bors[bot]
33d86effc9
Merge #2904
2904: Prepare release 3.0.0-beta.5 r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-17 16:10:55 +00:00
Pavan Kumar Sunkara
585e995811 Release 3.0.0-beta.5 2021-10-17 17:01:18 +01:00
Pavan Kumar Sunkara
e63760e461 Allow possible_values to take string vector reference
Makes it more backward compatible and flexible
2021-10-17 17:01:18 +01:00
bors[bot]
d3b33953de
Merge #2902
2902: Minor cosmetic: Place default/env/… on separate lines for multiline help output r=pksunkara a=jcaesar



Co-authored-by: Julius Michaelis <glitter@liftm.de>
2021-10-17 14:00:16 +00:00
Julius Michaelis
16af4f230a cosmetic: spec_vals on separate lines for long help 2021-10-17 22:43:06 +09:00
bors[bot]
98532ebddc
Merge #2903
2903: feat(generate): reduce dependencies of clap_generate (42 to 13) r=pksunkara a=rhysd



Co-authored-by: rhysd <lin90162@yahoo.co.jp>
2021-10-17 06:40:50 +00:00
rhysd
33efcf1665 feat(generate): reduce dependencies of clap_generate (42 to 13) 2021-10-17 14:31:16 +09:00
bors[bot]
1c2b09e57b
Merge #2890
2890: feat: Expose clap-style errors to users r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-17 00:12:07 +00:00
Ed Page
b9cc585997 feat: Expose clap-style errors to users
This gives users the basic error template for quick and dirty messages.
In addition to the lack of customization, they are not given anything to help
them with coloring or for programmayic use (info, source).

This is something I've wanted many times for one-off validation that
can't be expressed with clap's validation or it just wasn't worth
the hoops.  The more pressing need is for #2255, I need `clap_derive`
to be able to create error messages and `Error::with_description` seemed
too disjoint from the rest of the clap experience that it seemed like
users would immediately create issues about it showing up.

With this available, I've gone ahead and deprecated
`Error::with_description` (added in 58512f2fc), assuming this will be
sufficient for users needs (or they can use IO Errors as a back door).
I did so according to the pattern in #2718 despite us not being fully
resolved on that approach yet.
2021-10-16 19:03:17 -05:00
bors[bot]
d78d5a3744
Merge #2899
2899: Allow RegexSet for validator_regex r=epage a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-16 21:40:07 +00:00
Pavan Kumar Sunkara
7dc176ab2a Allow RegexSet for validator_regex 2021-10-16 22:30:52 +01:00
bors[bot]
badad6c088
Merge #2895
2895: fix(derive): Don't leak help headings r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-16 18:58:23 +00:00
bors[bot]
8647302296
Merge #2718
2718: fix: Ease clap2->clap3 migration with deprecations r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-16 17:52:21 +00:00
Ed Page
65e4bf232d fix(derive): Don't leak help headings
Before, when `flatten`ing, the struct you flattened in could set the
help heading for all the following arguments.  Now, we scope each
`flatten` to not do that.

I had originally intended to bake this into the initial / final methods
but that would have required some re-work to allow capturing state
between them that seemed unnecessary.

Fixes #2803
2021-10-16 11:21:16 -05:00
bors[bot]
6eacd8a747
Merge #2882
2882: fix(derive): Ensure App help_heading is applied r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-16 02:47:34 +00:00
bors[bot]
219d59a57a
Merge #2891
2891: refactor: Use USAGE_CODE constant r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-16 01:40:15 +00:00
Ed Page
d3c85773c0 refactor: Use USAGE_CODE constant
I missed a case in #2604.  This will help people discover the
documentation describing why we chose the code we did.
2021-10-15 19:39:00 -05:00
bors[bot]
b835ce9061
Merge #2817
2817: Add support for Multicall executables as subcommands with a Multicall setting r=pksunkara a=fishface60



Co-authored-by: Richard Maw <richard.maw@gmail.com>
2021-10-16 00:32:52 +00:00
bors[bot]
afd9efc108
Merge #2887
2887: fix(help): Partial fix for 'help help' r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 23:38:17 +00:00
Ed Page
81e877c6c2 fix(help): Partial fix for 'help help'
Who knew people need to ask `help` for how to use `help`?

While auditing `MultpleValues`, I saw commented out code.   Looks
its commit (f230cfedc) was part of a large refactor and updating that
part fell through the cracks.  Just simply updating it didn't quite get
it to work.  The advantage of this approach is it gets us closer to how
clap works on its own.

In clap 2.33.3, `cmd help help` looks like
```
myapp-help
Prints this message or the help of the given subcommand(s)

USAGE:
    test-clap help [subcommand]...

ARGS:
    <subcommand>...    The subcommand whose help message to display
```

But clap3 master looks like:
```
myapp

USAGE:
    myapp [SUBCOMMAND]

OPTIONS:
    -h, --help    Print custom help about text

SUBCOMMANDS:
    help      Print this message or the help of the given subcommand(s)
    subcmd
```

This change improves it to:
```
myapp-help

Print this message or the help of the given subcommand(s)

USAGE:
    myapp help [SUBCOMMAND]...

ARGS:
    <SUBCOMMAND>...    The subcommand whose help message to display

OPTIONS:
    -h, --help    Print custom help about text
```

We still have global arguments showing up (like `-h`) that will error but its
an improvement!  In general, I'd like to find a way to leverage clap's stanard
behavior for implementing this so we don't have to worry about any of these
corner cases in the future.

Note: compared to clap2, I changed `<subcommand>` to `<SUBCOMMAND>` because I
believe the standard convention is for value names to be all caps (e.g.
`clap_derive` has been updated to default to that).
2021-10-15 18:24:15 -05:00
bors[bot]
2795ccd70d
Merge #2888
2888: refactor(derive): Simplify 'error' handling r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 21:28:36 +00:00
Ed Page
7b56184175 refactor(derive): Simplify 'error' handling
Our goal is to not panic inside of the macro (e.g. #2255).  Currently,
we `.unwrap()` everywhere except when turning an `ArgMatches` into an
`enum`.  To handle `flatten`, we walk through each `flatten`ed enum to
see if it can be instantiated.  We don't want to mix this up with any of
the other eror cases (including further nested versions of this).

If we went straight to `Result<T>`, we'd have to differentiate this case
through the `ErrorKind` and `map_err` it in all other cases to prevent
it from bubbling up and confusing us.

Alternatively, we could do a more complicated type `Result<Option<T>>`
where the `Option` exists purely for this case and we can use type
checking to make sure we properly turn the `None`s into errors when
needed.

Or we can bypass all of this and just ask the `flatten`ed` subcommand if
it supports the current command.
2021-10-15 15:43:02 -05:00
Richard Maw
b92f2c0339 fixup! formatting lint 2021-10-15 21:14:26 +01:00
Richard Maw
636ecaffa2 fixup! make new tests compile but not run without unstable-multicall 2021-10-15 20:59:33 +01:00
Ed Page
bfd6f8d8e0
Merge pull request #2884 from epage/augment
fix(derive): Support 'update' with 'flatten'
2021-10-15 14:47:12 -05:00
Richard Maw
f7e9bfed80 fixup! Add unstable-multicall flag to CI workflows 2021-10-15 20:27:29 +01:00
Ed Page
a43da7ca61 fix: Ease clap2->clap3 migration with deprecations
- `App::with_defaults` was not included since that has been deprecated
  since 2.14
- `App::args_from_usage` does not have a close enough parallel in the
  new API, as far as I could tell
- `ArgMatches::usage` cannot have a thin wrapper around
  `App::generate_usage`.
- `App::write_*`: getting lazy, didn't seem like high value functions
- Any `Settings` (some things need to be figured out here)

This is a part of #2617
2021-10-15 14:19:16 -05:00
Ed Page
22edac66d9 fix(derive): Ensure App help_heading is applied
We normally set all app attributes at the end.  This can be changed but
will require some work to ensure
- Top-level item's doc cmment ins our over flattened
- We still support `Args` / `Subcommand` be used to initialize an `App` when
  creating a subcommand

In the mean time, this special cases `help_heading` to happen first.
We'll need this special casing anyways to address #2803 since we'll need
to capture the old help heading before addings args and then restore it
after.  I guess we could unconditionally do that but its extra work /
boilerplate for when people have to dig into their what the derives do.

Fixes #2785
2021-10-15 14:19:16 -05:00
Ed Page
7b3d3401c0 fix(derive): Support 'update' with 'flatten'
When working on #2803, I noticed a disprecancy in the augment
behavior between `Arg`s and `Subcommand`s that makes it so `Arg`s can't
be flattened with the update functionality.
2021-10-15 14:19:16 -05:00
bors[bot]
f9208ae4e3
Merge #2886
2886: docs: Encourage multiple_occurrences r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 17:57:07 +00:00
Ed Page
59497629e8 docs: Encourage multiple_occurrences
There were fewer occasions than I expected where the use of
`multiple_values` was superfluous and we could instead use the more
predictable `multiple_occurrences`.

In terms of the remaining `multiple` split work, #1772 will take care of the derive
behavior and #2692 will resolve any remaining issues with values vs
occurrences in positional arguments.

Fixes #2816
2021-10-15 11:41:40 -05:00
bors[bot]
4854986bb9
Merge #2883
2883: fix(app): Rename generaet_usage to render_usage r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 15:54:13 +00:00
Ed Page
6ee5fc4d5d fix(app): Rename generaet_usage to render_usage
This is inline with all of our other help-related functions that return
strings.

This is a part of #2164

BREAKING CHANEG: `App::generate_usage` (added in v3) ->
`App::render_usage`.
2021-10-15 09:36:44 -05:00
bors[bot]
cd00a9408a
Merge #2878
2878: fix: Give Arg::help_heading priority over App::help_heading r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 07:36:19 +00:00
Ed Page
7f05c15a5e fix: Give Arg::help_heading priority over App::help_heading
PR #1211 originally added `help_heading` with the current priority
(`App::help_heading` wins).

In #1958, the author had proposed to change this

> Note that I made the existing arg's heading a priority over the one in App::help_heading

This was reverted on reviewer request because

> Thanks for the priority explanation. Yes, please make the app's help
> heading a priority. I can see how it would be useful when people might
> want to reuse args.

Re-using args is an important use case but this makes life difficult
for anyone using `help_heading` with `clap_derive` because the user
can only call `App::help_heading` once per struct.  Derive users can't get
per-field granularity with `App::help_heading` like the builder API.

As a bonus, I think this will be the least surpising to users.  Users
generally expect the more generic specification (App) to be overridden by the
more specific specification (Arg).  Honestly, I had thought this PR is
how `help_heading` worked  until I dug into the code with #2872.

In the argument re-use cases, a workaround is for the reusable arguments
to **not** set their help_heading and require the caller to set it as
needed.

Fixes #2873
2021-10-14 18:23:10 -05:00
bors[bot]
089c4160cf
Merge #2879
2879: Improve bash generator r=pksunkara a=pksunkara



Co-authored-by: Ajeet D'Souza <98ajeet@gmail.com>
2021-10-14 22:04:07 +00:00
Ajeet D'Souza
cad1879ab2 Improve bash generator 2021-10-14 22:51:40 +01:00
bors[bot]
11453065c5
Merge #2871 #2872 #2876
2871: Better positional checks r=epage a=pksunkara



2872: Iterate on help_heading to prepare for derive support r=pksunkara a=epage



2876: Generate/bash: add possible_values to completion when available r=pksunkara a=nstinus



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
Co-authored-by: Ed Page <eopage@gmail.com>
Co-authored-by: Nicolas Stinus <nstinus@latourtrading.com>
2021-10-14 20:23:54 +00:00