Commit graph

3867 commits

Author SHA1 Message Date
Pavan Kumar Sunkara
6ea223bc6e
Merge pull request #2644 from ldm0/clippy
Fix clippy
2021-07-30 08:38:34 +01:00
Pavan Kumar Sunkara
ebc28c096f
Merge pull request #2642 from patrick-gu/master
Replace "Prints" with "Print" for default help and version commands
2021-07-30 08:35:49 +01:00
liudingming
44b7eee404 Fix clippy 2021-07-30 13:36:38 +08:00
patrick-gu
a4dc72ed19 Replace "Prints" with "Print" for default help and version commands 2021-07-29 20:23:25 -07:00
Pavan Kumar Sunkara
8ca62aa185
Merge pull request #2636 from epage/typo
fix(example): Use correct type in comment
2021-07-28 21:40:19 +01:00
Ed Page
c27b2e299c fix(example): Use correct type in comment
Fixes #2631
2021-07-28 10:34:48 -05:00
Pavan Kumar Sunkara
35db529b36
Merge pull request #2630 from epage/flatten
fix(derive): Allow partial update of flattened Subcommand arguments
2021-07-27 19:04:41 +01: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
5fbd764b06
Merge pull request #2622 from patrick-gu/master
Refactor creation of `App` and `Arg` from YAML
2021-07-27 10:31:55 +01: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
Pavan Kumar Sunkara
7ce5c36b42
Merge pull request #2612 from epage/default_value
feat(derive): Make it possible to use ArgEnum with default_value
2021-07-26 23:17:47 +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
patrick-gu
9b64ac2b45 Refactor creation of App and Arg from YAML
Improved the `impl`s of `From` for `&'help Yaml` to use expects with useful messages instead of unwraps. Also made changes to avoid potentially fetching redundant data from YAML hashes and unwrapping the same data multiple times. Finally, there are tests to ensure the panics are correct.
2021-07-25 15:24:43 -07: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
Pavan Kumar Sunkara
077d43beeb
Merge pull request #2606 from epage/subcommand
fix(derive): Allow partial update of Subcommand arguments
2021-07-25 14:34:37 +01:00
Pavan Kumar Sunkara
79e3b37ecc
Merge pull request #2604 from epage/exit
fix(exit): Be consistent in exit code
2021-07-25 14:32:47 +01:00
Pavan Kumar Sunkara
27311139c2
Merge pull request #2610 from ldm0/value_name
Print `value_name` `number_of_values` times with single value_name
2021-07-25 14:23:21 +01:00
Pavan Kumar Sunkara
378797a20e
Merge pull request #2609 from ldm0/default_val_usage
Don't show default_vals in smart usage
2021-07-25 14:20:29 +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
liudingming
62fa1e7454 Print value_name number_of_values times with single value_name 2021-07-21 03:38:58 +08:00
liudingming
6094520541 Don't show default_val in smart usage 2021-07-21 02:50:41 +08:00
Ed Page
6e24c849fb fix(exit): Be consistent in exit code
PR #1637 switched clap to report `64` on errors and then #1653 switch it
to `2`, but both missed a case.  This also documents the reason why inline
since I had to go and dig through the history to re-discover the
motivation.
2021-07-19 11:21:01 -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
Pavan Kumar Sunkara
8ff68080e6
Merge pull request #2603 from hosseind88/remove-a-redundant-word-in-AppSettings-NoBinaryName-enum-explanation
Remove a redundant word in AppSettings::NoBinaryName enum explanation
2021-07-19 15:03:17 +01:00
hosseind88
cc2e07ea61 Remove a redundant word in AppSettings::NoBinaryName enum explanation 2021-07-19 17:56:57 +04:30
Pavan Kumar Sunkara
d8f6878db8
Merge pull request #2593 from epage/skip
feat(derive): Allow skipping ArgEnum variants
2021-07-17 04:57:08 +01:00
Ed Page
c1e272ea6c feat(derive): Allow skipping ArgEnum variants
Depends on #2590
Fixes #2592
2021-07-16 17:04:20 -05:00
Pavan Kumar Sunkara
060c6da9ef
Merge pull request #2590 from epage/dead
fix(derive): Don't generate dead code
2021-07-16 22:57:29 +01: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
Pavan Kumar Sunkara
fbd8e6d742
Merge pull request #2587 from epage/sub
fix(derive): Allow subcommands to directly nest in subcommands
2021-07-16 21:39:05 +01: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
Pavan Kumar Sunkara
62588bd82c
Merge pull request #2586 from epage/args
fix(derive)!: Compile-error on nested subcommands
2021-07-16 16:44:21 +01:00
Pavan Kumar Sunkara
4beb1aa354
Merge pull request #2600 from jvbreen1/patch-1
Change some wording to be more inclusive
2021-07-16 15:33:14 +01:00
John Breen
a2e5cc2bec
Change some wording to be more inclusive 2021-07-15 17:03:25 -04: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
Pavan Kumar Sunkara
fbcf079e78
Merge pull request #2595 from epage/move
refactor: Move code to future trait locations
2021-07-14 23:32:52 +01:00
Pavan Kumar Sunkara
bc03c94e2e
Merge pull request #2594 from nirvdrum/patch-1
Fix a small typo in the README
2021-07-14 22:06:31 +01:00
Kevin Menard
171148873c
Fix a small typo in the README 2021-07-14 17:05:20 -04: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
Pavan Kumar Sunkara
af6f7af368
Merge pull request #2577 from tshepang/fix-links
fix remaining intra-doc links
2021-07-13 00:43:28 +01:00
Ed Page
3be79b9e1b
docs(derive): Update trait doc-comments (#2579)
* docs(derive): Update trait doc-comments

* Apply suggestions from code review

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-07-12 21:43:03 +01:00
Pavan Kumar Sunkara
006a5fed31
Merge pull request #2578 from codedust/patch-1
Fix grammar in `require_delimiter` fn docs
2021-07-11 11:21:20 +01:00