Commit graph

121 commits

Author SHA1 Message Date
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
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
rhysd
012f318c97 feat(doc): Fix many typos in docs, comments and codes found by typos-cli 2021-10-19 10:38:22 +09:00
Julius Michaelis
16af4f230a cosmetic: spec_vals on separate lines for long help 2021-10-17 22:43:06 +09: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
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
Ed Page
61c9e6265b fix(help)!: Merge OPTIONS / FLAGS default groups
For those that want the original behavior, you can usxe
`arg.help_heading(Some("FLAGS"))` on your flags.  Limitations:
- This will not give you a special sort order
- This will not get a `[FLAGS]` added to usage

For templates, we removed `{unified}` and `{flags}`.  To help people
catch these, a debug_assert was added.

I'm unsure but I think there might be a change in behavior in calcuating
when to show `[OPTION]` in usage.  The old code only looked at
`required` while flags looked only at arg groups.  We now look at both.

Ideally we'd add these in `_build` and remove special casing for
no-groups except in the sort order of groups.  I feel like thats best
left for later.

This also reduced the scope of `App`s public API.
`get_*_with_no_heading` seemed a bit specialized to be in the public
API.  #2853 looks at splitting it out into its own PR.

BREAKING CHANGE: Multiple
- `UnifiedHelpMessage` removed
- `{flags}` and `{unified}` are removed and will assert when present.
- `get_*_with_no_heading` removed

Fixes #2807
2021-10-13 11:42:10 -05:00
Ed Page
60c9c2e59a docs(derive): Use more-specific traits
This helps to raise visibility of the new derive traits.

I didn't touch ui tests because there were a lot and they didn't seem to
be as high value.
2021-10-12 07:51:11 -05:00
Pavan Kumar Sunkara
685601e002 fix: Add test for flattening struct in enum 2021-10-11 21:54:44 +01:00
Ed Page
6dd9d467ce fix(help)!: Consoldiate color settings
A lot of users expected `color` feature flag and `ColorAuto` etc to
control all colors.  Having this extra flag around is easy to miss and
adds to our overall settings bloat, making it harder to find settings
people want.

This completely removes it, rather than make it deprecated like
functions in #2617, because there is extra work to mark things
deprecated as Settings and we should decide on our strategy first before
investing time in addressing that issue.

Fixes #2806
2021-10-11 09:01:13 -05:00
Ed Page
d840d5650e fix(derive)!: Rename Clap to Parser.
Before #2005, `Clap` was a special trait that derived all clap traits it
detected were relevant (including an enum getting both `ArgEnum`,
`Clap`, and `Subcommand`).  Now, we have elevated `Clap`, `Args`,
`Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't
very descriptive.

This also helps further clarify the relationships so a crate providing
an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely
to choose the needed trait to derive.

Also, my proposed fix fo #2785 includes making `App` attributes almost
exclusively for `Clap`.  Clarifying the names/roles will help
communicate this.

For prior discussion, see #2583
2021-10-09 20:12:03 -05:00
bors[bot]
e3b23929b3
Merge #2823 #2824 #2827
2823: fix(derive): Subcommands not working within macro_rules r=epage a=epage



2824: docs(derive): Fix explanation on optional string list argument r=epage a=epage



2827: feat: Add backtraces to errors r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-07 18:49:59 +00:00
bors[bot]
6c2daef7a1
Merge #2821 #2822
2821: test(derive): Port structopt flatten coverage r=epage a=epage



2822: feat(derive): Add support for lower/upper in rename_all r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-07 16:02:20 +00:00
Ed Page
e42487f6e8 fix(derive): Subcommands not working within macro_rules
This carries over a test case from
https://github.com/TeXitoi/structopt/pull/448, and re-fixes it according
to the changes we've made since we forked.  I also tried to  identify
other cases and quote them to avoid playing whack-a-mole with this.

This is a part of #2809
2021-10-07 10:05:30 -05:00
Ed Page
f681e46414 test(derive): Port structopt flatten coverage
https://github.com/TeXitoi/structopt/pull/414 was ported in
a95195874 but the test was less exhaustive.  This updates our test to
match structopt's latest version of the test.

This is a part of #2809
2021-10-07 10:02:34 -05:00
Ed Page
e10b5281d6 feat(derive): Add support for lower/upper in rename_all
Some programs do not use anything to separate word boundaries.

For example a struct may contain the field `build_dir` while the flag is
`--builddir`.

This is a port of https://github.com/TeXitoi/structopt/pull/412

This is part of #2809
2021-10-07 10:02:34 -05:00
Ed Page
6594e28776
Merge pull request #2826 from epage/skip
feat(derive): Add skip attribute support for enum variants
2021-10-06 19:16:42 -05:00
Ed Page
16023cf157 feat(derive): Add skip attribute support for enum variants
> Resolves #493

This is a port of https://github.com/TeXitoi/structopt/pull/494

This is part of #2809
2021-10-06 13:52:02 -05:00
Ed Page
51c723a84f fix(derive): Fix the problem where the build fails due to the ambiguous type of map
> This PR closes #490. Please refer to #490 for the detail of the problem. Let me know if you want to make `convert_type` a function.

This is a port of https://github.com/TeXitoi/structopt/pull/491

This is part of #2809
2021-10-06 13:22:56 -05:00
Ed Page
6f95650a91
Merge pull request #2805 from epage/validate_default
fix(derive): Type check `default_value_t`
2021-10-06 08:54:59 -05:00
Ed Page
9afa08ff50 fix(derive): Support SubcommandsNegateReqs
Before there was no way to make `SubcommandsNegateReqs` with
`clap_derive` because it required a required field with a sentinel value
for when the required part was negated.  We blocked that.

This turned out simpler than I expected.

This came out of the discussion for #2255 but that issue is more
specifically about the panic, so not closing it.
2021-10-05 16:02:02 -05:00
Ed Page
d0b22b53ff fix(derive): Type check default_value_t
Fixes #2064
2021-10-04 13:02:47 -05:00
ModProg
08e8c53862 refactor(ArgEnum): replace unwrap with except, arg_value -> to_arg_value 2021-10-01 16:14:10 +02:00
ModProg
d53778ed5d fix ui 2021-09-29 19:31:05 +02:00
ModProg
480035ac9c ArgEnum: Slice instead of array, from_str in ArgEnum implemented 2021-09-29 18:33:43 +02:00
ModProg
ac1a9d6d13 address epage's remarks 2021-09-27 22:06:17 +02:00
ModProg
f002cdcc99 move alias implementation to ArgValue for derive 2021-09-27 01:18:47 +02:00
ModProg
b589a6ce06 feat(derive:arg_enum): use ArgValue in ArgEnum trait 2021-09-26 16:32:46 +02:00
corentin.regal
8df90fbd0e Allow subcmd name to be something else than a literal in clap derive 2021-09-06 09:13:20 +02:00
Ed Page
aeaf01e3e7 fix: Provide path to avoid UTF-8 panics
Before, validating UTF-8 was all-or-nothing and would cause a `panic` if
someone used the right API with non-UTF-8 input.

Now, all arguments are validated for UTF-8, unless opted-out.  This
ensures a non-panicing path forward at the cost of people using the
builder API that previously did `value_of_os` need to now set this flag.

Fixes #751
2021-08-18 14:15:18 -05:00
Pavan Kumar Sunkara
badcb3ac7b
Merge pull request #2684 from epage/update_ext
test: Cover external subcommand updates
2021-08-13 20:51:21 +01:00
Ed Page
2458d3934a test: Cover external subcommand updates
We don't know enough to do partial updates, so we are only doing full
updates.

Closes #2212
2021-08-13 12:33:12 -05:00
Ed Page
9a180c1511 feat(derive): Specify defaults by native expressions
Right now
- `default_value="something"` is a raw method
- `default_value` uses native types

This commit splits the meanings
- `default_value="something"` is a raw method
- `default_value_t` uses `T::default()`
- `default_value_t=expr` uses an expression that evaluates to `T`

This is meant to mirror the `value_of` / `value_of_t` API.

At the moment, this is limited to `T: Display` to work with clap's
default system.  Something we can look at in the future is a way to
loosen that restriction.  One quick win is to specialize when `arg_enum`
is set.  The main downside is complicating the processing of attributes
because it then means we need some processed before others.

Since this builds on `clap`s existing default system, this also means
users do not get any performance gains out of using `default_value_t`,
since we still need to parse it but we also need to convert it to a
string.

Fixes #1694
2021-08-13 12:20:54 -05:00
Ivan Tham
f484e2da11 Derive doc clap ordering for multiple Clap
Fix #2527
2021-08-11 23:31:00 +01:00
patrick-gu
eca8ba6098 Make multiple_values false with Option<Option<...>> 2021-08-01 14:50:31 -07:00
Pavan Kumar Sunkara
ff95eb2f5b
Merge pull request #2647 from clap-rs/msrv
Bump msrv to 1.54.0
2021-07-31 05:45:02 +01:00
Ed Page
52d3942ba6 fix(derive): Reduce compiler error noise
It looks like CI hasn't been running on this and we've introduced some
problems.  It looks like we had an off-by-one error in the check for
MSRV for deciding to run ui tests.
2021-07-30 10:19:21 +01:00
Ed Page
241d183b9c Bump MSRV to 1.54.0
- This makes it so `doc` compiles on stable

Fixes #2618
2021-07-30 10:19:21 +01:00
Ed Page
78aa86cfbb fix(derive): Don't mix implicit and explicit value_names
It turns out `value_name` appends, so by setting an implicit and
explicit `value_name`, the user gets both and `num_vals=2`.

There is still a question on `value_name` and whether its documentation
or behavior needs updating.  If that changes, then this can be
simplified by reverting back.

Fixes #2632
2021-07-28 09:46:13 -05:00
Ed Page
6a70c744e0 fix(derive): Allow partial update of flattened Subcommand arguments
When using `#[clap(flatten)]` inside of a `Subcommand`, we would do a
`from` instead of an `update`.

The challenge is knowing when we are
going into a flattened subcommand vs changing the variant.  To resolve
this, I added a `Subcommand:has_subcommand(name)` trait method that we
generate, so we can ask.
2021-07-27 12:14:53 -05:00
Pavan Kumar Sunkara
34a0674c92
Merge pull request #2625 from epage/sub-sub
fix(derive): Allow partial update of Sub-Subcommands
2021-07-27 09:07:20 +01:00
Pavan Kumar Sunkara
3b2d23947b
Merge pull request #2611 from epage/value_name
fix(derive): Follow value_name convention
2021-07-27 09:06:39 +01:00
Ed Page
d643fb3c32 feat(derive): Make it possible to use ArgEnum with default_value
This doesn't solve the problem end-to-end but at least makes it possible
to solve by the user and improve in the future.
2021-07-26 10:33:14 -05:00
Ed Page
746eb9d7bd fix(derive): Allow partial update of Sub-Subcommands
When using `#[clap(subcommand)]` inside of a Subcommand, we didn't
properly do an `update` but a `from`.

This is a part of #2605
2021-07-26 10:03:10 -05:00
Ed Page
c485ae517b fix(derive): Follow value_name convention
I debated putting this fix inside of the Builder API but I figure this
makes it so you "pay for what you use", with the derive API giving it to
you "for free".

A potential next step is to improve the default value name.  I tend to
use value_name to hint at how to use an argument, which correlates with
types.  We could add a
`ValueName::value_name(fallback: &str) -> &str` with impls for common
types, so we get more of a usage-based result.

Fixes #2608
2021-07-26 10:01:32 -05:00
Ed Page
976561869c fix(derive): Allow partial update of Subcommand arguments
Before, when doing an `update` involving subcommands, we generated
parsing rules for the `from` case instead, requiring all arguments to be
present.

This switches us to descending into `update` code and adds tests to
verify it works.

This is a part of #2605
2021-07-19 11:13:22 -05:00
Ed Page
c1e272ea6c feat(derive): Allow skipping ArgEnum variants
Depends on #2590
Fixes #2592
2021-07-16 17:04:20 -05:00