Commit graph

439 commits

Author SHA1 Message Date
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
7761cf00d7 docs(derive): Fix explanation on optional string list argument
This is a port of https://github.com/TeXitoi/structopt/pull/450

This is a part of #2809
2021-10-07 10:02:34 -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
74799ea916 Revert structopt #325
https://github.com/TeXitoi/structopt/pull/325 special cased `version`
because a default method would be added if the user did nothing, which
caused problems when nesting subcommands.  We no longer apply that
default method and the highest item in the chain always has precedence,
so this can be simplified / clarified.
2021-10-06 19:20:15 -05:00
Ed Page
412071a134 refactor: Be consistent in adding methods last
This will unblock us from removing the `version` hack because we'll
always get the right precedence.

Later we can explore ways of moving the app methods to being done first.
The big problem is with `#[clap(subcommand)]` because we need to call
those app methods on the subcommands `App` *and* override them with app
methods on the variant, requiring the app methods to be last to get
precedence.
2021-10-06 19:19:31 -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
e62a92f260
Merge pull request #2810 from epage/license
docs: Ensure all crates have license files
2021-10-06 08:55:25 -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
6c6b97daa8 docs: Ensure all crates have license files
In #2270, its brought up to solve this at the `cargo workspace publish`
level.  However, copying the files is a 5s fix without any design work,
it doesn't seem like support within an external tool should block us
from getting this fix into users hands.  Once `cargo workspace publish`
supports this and if we are still using it, we can re-evaluate.

Fixes #2270
2021-10-04 14:45:31 -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
15fcf814c2 fix dummies 2021-09-29 19:05:16 +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
76f7211d8b small changes 2021-09-27 01:29:10 +02:00
ModProg
f002cdcc99 move alias implementation to ArgValue for derive 2021-09-27 01:18:47 +02:00
Roland Fredenhagen
88d7d02555 Working Implementation 2021-09-26 16:32:46 +02:00
ModProg
b589a6ce06 feat(derive:arg_enum): use ArgValue in ArgEnum trait 2021-09-26 16:32:46 +02:00
Roland Fredenhagen
5580e8c465
ArgValue builder (#2758)
* feat(arg_value): ArgValue can be used for possible_values

Through the ArgValue it is possible:

* `hide` possible_values from showing in completion, help and validation
* add `about` to possible_values in completion

* Resolved a few change-requests by epage

* make clippy happy

* add ArgValue::get_visible_value

* remove verbose destructering

* rename ArgValue::get_hidden to ArgValue::is_hidden

* add test for help output of hidden ArgValues

* Documentation for ArgValue

There is an issue that required to implement From<&ArgValue> for
ArgValue. We should probably find a solution without that.

* fix requested changes by epage

* fix formatting

* add deref in possible_values call to remove From<&&str>

* make clippy happy

* use copied() instad of map(|v|*v)

* Finishing up for merge, hopefully

* changes requested by pksunkara
2021-09-19 10:29:09 +00: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
Sven-Hendrik Haase
2f8f55e64b
Fix keyvalue example
This was broken earlier due to 3f94d17c71 not
taking into account this example.

Fixes #2746.
2021-08-30 04:52:35 +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
502dd78828 fix(derive): Don't produce warnings
I did some digging to root cause this but gave up and suppressed it,
like others.  Warnings like this also come with a cost of code-gen
complexity.

Fixes #2712
2021-08-17 20:53:12 -05:00
Pavan Kumar Sunkara
52be134949 Release 3.0.0-beta.4
clap@3.0.0-beta.4
clap_derive@3.0.0-beta.4
clap_generate@3.0.0-beta.4

Generated by cargo-workspaces
2021-08-14 23:40:49 +01:00
Pavan Kumar Sunkara
73b28fb104 Release 3.0.0-beta.3
clap@3.0.0-beta.3
clap_derive@3.0.0-beta.3
clap_generate@3.0.0-beta.3

Generated by cargo-workspaces
2021-08-14 23:01:13 +01:00
Ed Page
2eb22e2b36 fix!: value_name/value_names should not append
Instead they should behave like `default_value`/`default_values`.

In implementingt this, I didn't see any reason to be using a `VecMap`.
In fact, this helped simplify the code / make intent clearer.

With this, we are also able to simplify the derive macro work from #2633.

Fixes #2634

BREAKING CHANGE: `value_name`/`value_names` always overwrite, rather
than append.  We expect the impact to be minimal.
2021-08-13 15:37:03 -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
Pavan Kumar Sunkara
6994be4f15 Remove doc feature 2021-07-30 22:49:11 +01:00
Pavan Kumar Sunkara
75445b974e
Merge pull request #2633 from epage/value_name
fix(derive): Don't mix implicit and explicit `value_name`s
2021-07-30 10:40:33 +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
patrick-gu
a4dc72ed19 Replace "Prints" with "Print" for default help and version commands 2021-07-29 20:23:25 -07: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
Pavan Kumar Sunkara
610d56d1c6
Merge pull request #2614 from epage/unwrap
fix: Provide context for panics
2021-07-25 15:12:06 +01:00
Ed Page
8087811136 fix: Provide context for panics
One of the challenges with #2255 is for the user to discover whats going
wrong.  This helps by at least telling people how they got into a bad
state and we can search for the code within the derive.
2021-07-21 16:53:05 -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
Ed Page
a8ba4c3b73 fix(derive): Don't generate dead code
When debugging #2586, I noticed we were developing match cases for
variant names that were flattened.  At minimum, this is dead code and at
worst this could cause the wrong behavior if a user does an update with
one of those names.

Depends on #2587

Fixes #2588
2021-07-16 15:39:52 -05:00
Ed Page
48356c34fb fix(derive): Allow subcommands to directly nest in subcommands
`structopt` originally allowed
```
pub enum Opt {
  Daemon(DaemonCommand),
}

pub enum DaemonCommand {
  Start,
  Stop,
}
```

This was partially broken in #1681 where `$ cmd daemon start` works but `cmd daemon`,
panics.  Originally, `structopt` relied on exposing the implementation
details of a derived type by providing a `is_subcommand` option, so we'd
know whether to provide `SubcommandRequiredElseHelp` or not.  This was
removed in #1681

Fixes #2005
2021-07-16 14:58:45 -05:00
Ed Page
53a9802ab2 chore(derive): Ensure license is recorded for subcommand 2021-07-15 12:04:04 -05:00
Ed Page
7f08773a5a fix(derive)!: Compile-error on nested subcommands
Before, partial command lines would panic at runtime.  Now it'll be a
compile error

For example:
```
pub enum Opt {
  Daemon(DaemonCommand),
}

pub enum DaemonCommand {
  Start,
  Stop,
}
```

Gives:
```
error[E0277]: the trait bound `DaemonCommand: clap::Args` is not satisfied
   --> clap_derive/tests/subcommands.rs:297:16
    |
297 |         Daemon(DaemonCommand),
    |                ^^^^^^^^^^^^^ the trait `clap::Args` is not implemented for `DaemonCommand`
    |
    = note: required by `augment_args`
```

To nest this, you currently need `enum -> struct -> enum`.  A later
change will make it so you can use the `subcommand` attribute within
enums to cover this case.

This is a part of #2005
2021-07-15 11:45:13 -05:00
Ed Page
507f0bf1cc refactor(derive): Move into_app into coupled derives 2021-07-14 16:01:47 -05:00
Ed Page
f6fa3771a6 refactor(derive): Order args.rs by use 2021-07-14 15:55:31 -05:00
Ed Page
58dd1d5c5a refactor(derive): Move from_arg_matches into coupled derives 2021-07-14 15:55:03 -05:00
Pavan Kumar Sunkara
894be6799c
Merge pull request #2585 from epage/argenum
fix(derive): `Clap` should not derive `ArgEnum`
2021-07-14 18:01:31 +01:00
Ed Page
6cc76e7237 fix(derive): Clap should not derive ArgEnum
While having convinience derives can be helpful, deriving traits that
are not used in similar situations (`Clap` and `ArgEnum`) can make
things harder
- From a user, derives are opaque and create uncertainty on how to use
  the API if not kept crystal clear (deriving a name gives you the trait
  by that name)
- This makes documentation harder to write and read
- You can use types in unintended places, which is made worse for crate
  APIs because changing this breaks compatibility.

Fixes #2584
2021-07-14 10:50:26 -05:00
Tshepang Lekhonkhobe
b4eddf158d fix remaining intra-doc links 2021-07-10 21:00:34 +02:00
Rémi Lauzier
c4f534228b
Fix some nightly clippy warnings 2021-06-16 23:25:13 -04:00
Pavan Kumar Sunkara
3f94d17c71 Removed Arg::multiple 2021-06-16 07:17:11 +01:00
Eric Langlois
c20acaf2d4 Derived ArgEnum::from_str returns Err instead of panicking
ArgEnum is public so it is possible for users to call it with
a non-variant input string.
2021-06-08 16:40:12 -04:00
Pavan Kumar Sunkara
94ce18c399 Update badges 2021-05-25 23:19:32 +01:00
Felipe Sere
46cd4fe664 Run fmt 2021-05-19 19:43:06 +01:00
Felipe Sere
6bac0c53bf Rename flag parameter to not clash with subcommand 2021-05-19 19:42:39 +01:00
Felipe Sere
856de610a2 Create a separate test for from_global 2021-05-18 21:35:49 +01:00
Kat Marchán
814b56dccb feat(derive): Add support from inheriting global options in subcommands 2021-05-18 17:39:51 +01:00
Donough Liu
2a921d4cda Fix clippy warnings. 2021-05-07 19:05:18 +00:00
liudingming
4dfc900a99 Clippy fix 2021-05-07 15:20:03 +08:00
Pavan Kumar Sunkara
99d4aba95c Remove azure pipelines 2021-04-13 22:46:24 +01:00
Pavan Kumar Sunkara
3c9cc0cf91 Specify dep patch versions 2021-04-11 10:38:13 +01:00
Pavan Kumar Sunkara
4e3b4589ee
Merge pull request #2411 from clap-rs/upgrader
Cleanup and add changelog
2021-03-14 14:00:16 +05:30
Pavan Kumar Sunkara
d9fb11eba2 Apply cargo-intraconv 2021-03-13 14:11:47 +05:30
Pavan Kumar Sunkara
49954c28ad Remove unstable feature flag 2021-03-13 11:40:56 +05:30
Omar El Halabi
777e0f43cb fix: subcommand with field name subcmd compilation 2021-03-10 19:49:41 +02:00
ldm0
2b0f0d3e1a Implement NoEquals error 2021-03-09 17:56:57 +00:00
Logan SQUIREL
3c049b4e22
Fix compatibility with help2man output (see #1432)
Change default help template:
- The new template introduce new lines before and after
author/about sections.
- Add help template placeholders:
    - about-section
    - author-section
- Documentation of new placeholders in clap::App::help_template
- Update all unit tests by incorporating new lines
2021-02-27 16:20:52 +01:00
Logan SQUIREL
cd8660fbd0
Fix issue #2181
- help / version flag report correct application name when generated
with clap_derive and an Enum.
- add clap_derive unit tests for application name:
  file: clap_derive/tests/app_name.rs
  tests: app_name_in_[short|long]_[help|version]_from_[struct|enum]()
2021-02-22 15:01:02 +01:00
ldm0
a684e9a51d Bump version-sync version 2021-02-14 09:51:23 +00:00
ldm0
580d8d2c63 Fix part of the non_fmt_panic 2021-02-12 17:35:15 +00:00
Pavan Kumar Sunkara
1bd902370a Add tests for mut_arg on help and version 2021-02-07 15:54:24 +00:00
Donough Liu
6968f340c3 Fix clippy warnings 2021-01-19 02:24:58 +08:00
David Yamnitsky
09014258cb Use clap instead of ::clap in clap_derive 2020-12-15 15:20:21 -05:00
Pavan Kumar Sunkara
ad9f97f402 Fix ui tests 2020-11-28 19:16:58 +00:00
Aaron Hill
6dc8353fe2
Fix hygiene of arg_matches parameter
In the `Clap` derive macro, a function parameter named `arg_matches` is
generated using `quote!` - as a result, this parameter ends up with
call-site hygiene. However, `arg_matches` is written literally within
several `quote_spanned!` blocks, which generate an `arg_matches` token
with the hygiene of whatever span was passed to `quote_spanned!`.

If these two hygienes are different (for example, if the user invokes
the derive macro from a `macro_rules!` macro), then a usage of
`arg_matches` may not resolve to the `arg_matches` parameter definition.

This commit changes the generation of `arg_matches` identifiers to
always use `quote!`, ensuring that they will always be considered the
'same' identifier by Rust.
2020-11-28 12:22:57 -05:00
Pavan Kumar Sunkara
56aeb155e1 Test rust regression 2020-11-28 11:47:18 +00:00
Luca Barbato
d18ff58391 Add a skip test 2020-11-14 11:09:39 +01:00
Luca Barbato
3e51839383 Rename the update trait methods 2020-11-14 10:58:30 +01:00
Luca Barbato
ac3e5f9a8f Factor out argument parsing generation 2020-11-14 10:53:13 +01:00
Luca Barbato
7a5c12e79a Avoid a level of indirection for augment_*subcommand 2020-11-14 10:17:13 +01:00
Luca Barbato
77e4e65e31 Address new clippy lints 2020-11-14 10:17:13 +01:00
Luca Barbato
9ebb46d65c Test for partial updates 2020-11-14 10:17:13 +01:00
Luca Barbato
5d342a7438 Update to the new from_subcommand logic 2020-11-14 10:17:13 +01:00
Luca Barbato
a9276576d7 wip: Add a variant for augment* for updates 2020-11-14 10:17:13 +01:00
Luca Barbato
8b6255057d wip: Complete update_subcommand
external subcommand updating is equivalent to replace it
2020-11-14 10:17:13 +01:00
Luca Barbato
646b3fe811 wip: Add tests and user-facing functions 2020-11-14 10:17:13 +01:00
Luca Barbato
d1fc83a8fa wip: Add update_from_arg_matches to FromArgMatches 2020-11-14 10:17:13 +01:00
Pavan Kumar Sunkara
d6e2246aab Rename setting DisableVersion => DisableVersionFlag 2020-10-24 16:03:12 +02:00
Wim Looman
b31df047b8 Attach validation error as Error::source 2020-10-13 22:13:04 +02:00
Marti Raudsepp
bc7cc4fbab Add examples for using value_hint with clap_derive
Also tweaked clap_generate example a little.
2020-10-10 00:11:44 +03:00
Pavan Kumar Sunkara
b931e25c79 Update MSRV to 1.42 2020-10-09 17:04:46 +02:00
Pavan Kumar Sunkara
d881a1185b Release 3.0.0-beta.2
clap@3.0.0-beta.2
clap_derive@3.0.0-beta.2
clap_generate@3.0.0-beta.2

Generated by cargo-workspaces
2020-09-18 20:32:41 +02: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
bors[bot]
ebecccd009
Merge #2110
2110: Allow flatten with doc comments r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-08-26 07:13:34 +00:00
CreepySkeleton
a951958748 Allow flatten with doc comments 2020-08-25 20:20:56 +03:00
Rémy Greinhofer
2a2cf81977 Update the env var example for derive
Updates the derive example handling environment variables to illustrate
the case where it contains a sensitive value which should not be
displayed on the help screen.

Closes https://github.com/clap-rs/clap/issues/2101
2020-08-23 18:18:25 -05:00
aspen
96b7fd454b
Forbid all unsafe code. 2020-08-20 18:38:40 -04:00
Kevin K
609202e2a0 wip: clap_derive docs 2020-08-11 15:21:57 +02:00
CreepySkeleton
f0044d205d Remove a redundant lifetime 2020-08-05 22:33:51 +03:00
CreepySkeleton
e6cc49ecde Adjust derive 2020-08-05 17:07:13 +03:00
João Marcos
24760bc261 style: replacing yml with yaml for consistency 2020-07-20 20:58:34 -03:00
Marti Raudsepp
594c535ba2 Fix various typos in docs & code
Most errors detected and fixed with Topy (https://github.com/intgr/topy),
all verified by hand.
2020-07-19 03:10:28 +03:00
bors[bot]
e8d46f4036
Merge #1989
1989: Replace macros with proper functions r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-07-06 18:51:07 +00:00
CreepySkeleton
51d0b31105 Fix test 2020-07-06 17:26:53 +03:00
Aaron Hill
c837b28552
fix(clap_derive): Unwrap syn::TypeGroup when checking field types
Due to macro expansions, a `syn` type may be wrapped in multiple
'layers' of `syn::Type::Group`. However, `clap_derive` currently does
not check for `syn::Type::Group`, which will cause an `Option` (along
with other matched types) to fail to be detected when it results from a
macro expansion.

This commit 'unwraps' outer type groups before checking the
user-provided types against well-known types. Currently, these groups
may not be present due to a rustc bug (rust-lang/rust#43081)

However, once https://github.com/rust-lang/rust/pull/73084 is merged,
these groups will be present in more cases. This commit makes `clap`
compatible with both older and newer versions of rustc.
2020-06-29 11:25:55 -04:00
CreepySkeleton
f904bebd9a Ditch find_subcnd*! and match_alias! 2020-06-27 04:30:02 +03:00
bors[bot]
ca27d50ab2
Merge #1975
1975: fix: Use character instead of string for Arg::Short r=CreepySkeleton a=lanesawyer



Co-authored-by: Lane Sawyer <github@lanesawyer.dev>
2020-06-27 01:14:20 +00:00
Luca Barbato
081f3e865c Fix the external command subtype check 2020-06-25 13:52:14 +02:00
Lane Sawyer
392effe319 fix: Use character instead of string for Arg::Short
This PR switches the Arg::Short macro to take a character instead of a string. It removes the hacky code in the Method to_token method and implements the logic for Short when parsing the clap derive arguments.

Fixes #1815.
2020-06-17 09:45:05 -07:00
Pavan Kumar Sunkara
8bd1f1a9d3 Started on automatic upgrader 2020-06-10 09:48:37 +02:00
Andreas Steding
f3a9975085 fix: cargo fmt + clippy 2020-06-08 18:40:11 +02:00
Paolo Barbolini
d771d6debd chore(Cargo.toml): bump proc-macro-error to 1 2020-05-29 00:13:17 +02:00
Pavan Kumar Sunkara
fe52d77f4e Allow separate derives, but do not give examples 2020-05-15 09:51:42 +02:00
Pavan Kumar Sunkara
7bc282dd4e Rename with_name to new for Arg & ArgGroup 2020-05-14 22:50:56 +02:00
Pavan Kumar Sunkara
b562ce4d63 Some modifications to allow cargo verification to work 2020-05-03 11:48:01 +02:00
bors[bot]
99e862945e
Merge #1883
1883: External subcommand r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-05-01 17:59:32 +00: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
ec6b6e1e36 Make validator take &str instead of String 2020-05-01 14:21:11 +03:00
CreepySkeleton
ee463ba834 Make extrernal_subcommand ALMOST work 2020-04-30 20:20:21 +03:00
CreepySkeleton
3b418fe1a1 Cleaning 2020-04-30 15:11:39 +03:00
Pavan Kumar Sunkara
68ce9dd6ec Rename trybuild file to ui 2020-04-28 11:39:30 +02:00
Pavan Kumar Sunkara
7616a5fa2e Implemented arg_enum for option and vec 2020-04-28 11:35:47 +02:00
creativcoder
d0abb378b0 cargo fmt 2020-04-27 20:41:41 +05:30
creativcoder
9c8c06dd8c Fix test for about method resolution in clap_derive 2020-04-27 02:42:07 +05:30
creativcoder
92d5920748 Updated test and usage of older help APIs with about 2020-04-27 02:42:07 +05:30
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
dbe6ac01f6 Clean up arg_enum 2020-04-22 14:38:16 +02:00
Pavan Kumar Sunkara
c4c6c35da7 Added alias support for arg_enum 2020-04-22 14:38:09 +02:00
Pavan Kumar Sunkara
01c179f527 Added arg_enum support 2020-04-22 14:37:45 +02:00
Pavan Kumar Sunkara
c1ab22c3c9 Remove unneeded paths 2020-04-22 09:33:39 +02:00
Pavan Kumar Sunkara
070bd50b28 Finished color refactor 2020-04-16 12:51:26 +02:00
Pavan Kumar Sunkara
b45746feff Remove some defaults from profiles 2020-04-10 17:19:26 +02:00
Pavan Kumar Sunkara
cceb29623a Remove nightly feature 2020-04-10 10:42:25 +02:00
Pavan Kumar Sunkara
f0a216036b Fix some issues 2020-04-09 19:41:33 +02:00
CreepySkeleton
b61a807728 Fix clippy and bump MSRV 2020-03-13 22:41:40 +03:00
CreepySkeleton
1cff11109e Fix CI 2020-03-13 20:51:41 +03:00
CreepySkeleton
5d9ef1527f Fix warnings in tests & examples 2020-03-05 13:40:25 +03:00
CreepySkeleton
bfc850e99a Suppress warnings in generated code 2020-03-05 11:35:21 +03:00
CreepySkeleton
d466a56aa1 Fix benches 2020-03-04 21:31:18 +03:00
Pavan Kumar Sunkara
d8d29aea13 Remove every proc_macro_derive except Clap 2020-03-02 16:28:35 +01:00
Pavan Kumar Sunkara
0c22a9df6c Added support for unit-struct 2020-03-02 11:46:40 +01: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
bors[bot]
a2dfbec2bc
Merge #1689
1689: Remove some mentioning of structopt r=TeXitoi a=CreepySkeleton

A work on #1671. Attention! It doesn't close it just yet

Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-13 17:37:28 +00:00
CreepySkeleton
28ef1e91d4
Remove some mentioning of structopt 2020-02-13 18:29:51 +03:00
CreepySkeleton
43acfa00f4
Implement derive traits for Box<T> 2020-02-13 18:21:01 +03:00
bors[bot]
12df8cb078
Merge #1681
1681: WIP: Extract subcommands into separate trait r=pksunkara a=CreepySkeleton

Not-yet-working-but-almost-there "multiple traits" approach. More or less done, what's left is to catch some bugs and adapt tests/examples.

For the record: it took so long because of RL stuff (who would have thought?) and because [there was a detailed description of the experience I've had here, but it was deleted because it contained a lot of profanity and emotional notes]. 

As the only person alive that understands how the derive works (if you won't blow your own horn, nobody will do it for you, yeah), I'd like to made a statement: we Do need the refactoring.

Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-12 20:42:32 +00:00
CreepySkeleton
ae574df2f9
Extract subcommands into separate trait 2020-02-12 23:15:05 +03:00
Pavan Kumar Sunkara
970d7140a3 Use 'Clap Maintainers' as authors 2020-02-10 20:16:25 +01:00
bors[bot]
ad5606b5a0
Merge #1678
1678: Refactor clap_generate r=CreepySkeleton a=pksunkara

I have copied the code from [clap_generate]( https://github.com/clap-rs/clap_generate) and refactored the structure a bit.

This new structure will allow people to write their own generators using our `Generator` trait which will contain some helpers (Still working on polishing them).

Co-authored-by: Ole Martin Ruud <barskern@outlook.com>
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-02-08 15:00:50 +00:00
Pavan Kumar Sunkara
33f47acc67 Refactor clap_generate 2020-02-07 07:52:04 +01:00
Pavan Kumar Sunkara
5b3a0dff9c Remove extern & macro_use where possible 2020-02-07 07:34:01 +01:00
CreepySkeleton
8221c4f367 Get rid of #[clap(no_version)] 2020-02-05 16:54:58 +03:00
bors[bot]
509ac33a20
Merge #1664
1664: Import structopt r=pksunkara a=CreepySkeleton

OK, here is about 50% of what's left to import.

`impl StructOpt for Box<impl StructOpt>` is not imported because layouts of `StructOpt` and `Clap` are too different. I'll work it out after the import is done.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/clap-rs/clap/1664)
<!-- Reviewable:end -->


Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
Co-authored-by: David McNeil <mcneil.david2@gmail.com>
2020-02-05 08:43:57 +00:00
CreepySkeleton
0b8f274078 Fix tests 2020-02-05 10:13:39 +03:00
CreepySkeleton
1b2c4344cb Fix visibility errors 2020-02-05 09:41:51 +03:00
David McNeil
62c4266daf Fix verbatim_doc_comment on fields
Signed-off-by: David McNeil <mcneil.david2@gmail.com>
2020-02-05 09:35:21 +03:00
CreepySkeleton
c40eb88d5b Less another one 2020-02-05 09:35:01 +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
596bdec856 Bugfix #324
Fixes https://github.com/TeXitoi/structopt/issues/324
2020-02-04 17:07:39 +03:00
CreepySkeleton
cf11d46373 Default value for default_value (yeah, sounds awkward) 2020-02-04 11:40:01 +03:00
Pavan Kumar Sunkara
4d2c8ffa6b Update Cargo.toml files 2020-02-04 09:11:33 +01:00
CreepySkeleton
5aafe9eaaf Pre release tweaks and changelog 2020-02-04 11:10:47 +03:00
CreepySkeleton
3b11f9af25 Consistent doc comments (#296) 2020-02-03 18:20:08 +03:00
CreepySkeleton
0851fb0266 Introduce #[structopt(rename_all_env)] 2020-02-03 17:56:17 +03:00
Pavan Kumar Sunkara
dd75cee72c fix: Clippy should pass 2020-02-01 06:48:50 +01:00
Pavan Kumar Sunkara
8e4a189ab0 fmt: Use standardized rustfmt rules 2020-01-31 18:37:56 +01:00
lzutao
dbc7988d23
Bump rustversion to stable release v1 2020-01-31 14:58:00 +07:00
Pavan Kumar Sunkara
afa9ec5e32 Address review comments
Co-Authored-By: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-01-19 06:08:22 +05:30
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