Commit graph

72 commits

Author SHA1 Message Date
Ed Page
c1e272ea6c feat(derive): Allow skipping ArgEnum variants
Depends on #2590
Fixes #2592
2021-07-16 17:04:20 -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
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
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
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
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
580d8d2c63 Fix part of the non_fmt_panic 2021-02-12 17:35:15 +00:00
Donough Liu
6968f340c3 Fix clippy warnings 2021-01-19 02:24:58 +08:00
Pavan Kumar Sunkara
ad9f97f402 Fix ui tests 2020-11-28 19:16:58 +00:00
Luca Barbato
d18ff58391 Add a skip test 2020-11-14 11:09:39 +01:00
Luca Barbato
9ebb46d65c Test for partial updates 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
Wim Looman
b31df047b8 Attach validation error as Error::source 2020-10-13 22:13:04 +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
CreepySkeleton
a951958748 Allow flatten with doc comments 2020-08-25 20:20:56 +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
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
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
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
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
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
070bd50b28 Finished color refactor 2020-04-16 12:51:26 +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
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