Commit graph

34 commits

Author SHA1 Message Date
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
Pavan Kumar Sunkara
685601e002 fix: Add test for flattening struct in enum 2021-10-11 21:54:44 +01: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
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
d53778ed5d fix ui 2021-09-29 19:31:05 +02:00
ModProg
ac1a9d6d13 address epage's remarks 2021-09-27 22:06:17 +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
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
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
53a9802ab2 chore(derive): Ensure license is recorded for subcommand 2021-07-15 12:04:04 -05:00
bors[bot]
16f92288f1
Merge #2115
2115: Adjust stderr files r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-08-28 11:31:47 +00:00
CreepySkeleton
f97b4cb1c7 Adjust stderr files 2020-08-28 13:51:58 +03:00
CreepySkeleton
a951958748 Allow flatten with doc comments 2020-08-25 20:20:56 +03:00
Luca Barbato
081f3e865c Fix the external command subtype check 2020-06-25 13:52:14 +02:00
Pavan Kumar Sunkara
fe52d77f4e Allow separate derives, but do not give examples 2020-05-15 09:51:42 +02:00
CreepySkeleton
a21372e9ed Fix ui tests 2020-05-01 20:09:55 +03:00
CreepySkeleton
6bdb6d9b2e Marry AllowExternalSubcommands with SubcommandRequiredElse* 2020-05-01 15:33:36 +03:00
CreepySkeleton
ee463ba834 Make extrernal_subcommand ALMOST work 2020-04-30 20:20:21 +03:00
CreepySkeleton
2e959d6c71 Update tests 2020-04-24 11:15:55 +03:00
Pavan Kumar Sunkara
ea637b22eb Apply suggestions from code review
Co-Authored-By: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-04-22 18:28:56 +02:00
Pavan Kumar Sunkara
01c179f527 Added arg_enum support 2020-04-22 14:37:45 +02:00
CreepySkeleton
1cff11109e Fix CI 2020-03-13 20:51:41 +03:00
CreepySkeleton
3f314ce39e Use full span information whenever possible 2020-02-13 21:47:42 +03:00
CreepySkeleton
9a15e47af0 Fix dummy implementations 2020-02-13 21:46:33 +03:00
CreepySkeleton
ae574df2f9
Extract subcommands into separate trait 2020-02-12 23:15:05 +03:00
CreepySkeleton
c7c7e5113c One less hack 2020-02-05 09:34:23 +03:00
Cecile Tonglet
8f3eb4623e Implemented: flatten on enums
Fixes #327
2020-02-05 09:10:59 +03:00
CreepySkeleton
cf11d46373 Default value for default_value (yeah, sounds awkward) 2020-02-04 11:40:01 +03:00
CreepySkeleton
5aafe9eaaf Pre release tweaks and changelog 2020-02-04 11:10:47 +03:00
Pavan Kumar Sunkara
7e0d820aa6 Run clap_derive tests in CI 2020-01-18 19:04:11 +05:30
Pavan Kumar Sunkara
5e8f424dfe Merged clap_derive using git-subtree 2020-01-18 17:40:07 +05:30