Commit graph

743 commits

Author SHA1 Message Date
Ed Page
9d482d00ba feat(error): Show possible values when none are supplied
This is inspired by cargo which allows you to run `cargo test --test`
and it will list the possible tests (obviously we can't support that atm
because that requires a lot of runtime processing).  When we do have a
static list of possible values, we can at least show those.

Fixes #3320
2022-02-02 14:28:41 -06:00
Ed Page
6827491069 fix(error): Consistently respect possible values order
We respected it for `--help` but not error messages.

Fixes #1549
2022-02-02 13:58:58 -06:00
Ed Page
06aa418fa6 fix(error): Be more accurate in smart usage
For some errors, we use the unroll logic to get the list of required
arguments.  The usage then does the same, but without a matcher.  This
was causing the lists to not match.

As a side effect, this fixed an ordering issue where we were putting the
present arg after the not-present arg.  I assume its because we ended up
reporting the items twice but the first time is correctly ordered and
gets precedence.

This was split out of #3020
2022-02-02 13:30:23 -06:00
Ed Page
4538d618a7 refactor: Migrate off of .kind 2022-02-01 11:27:08 -06:00
Rob Donnelly
a19bca8a10 docs(error): Update link to explicit bool parser example 2022-01-31 21:58:54 -08:00
Peter Grayson
7eea7d27ad
fix(help): Optional arg values in brackets
When an Arg uses .min_values(0), that arg's value(s) are effectively
optional. This is conventionaly denoted in help messages by wrapping the
arg's values in square brackets. For example:

    --foo[=value]
    --bar [value]

This kind of argument can be seen in the wild in many git commands; e.g.
git-status(1).

Signed-off-by: Peter Grayson <pete@jpgrayson.net>
2022-01-26 12:03:23 -05:00
Ed Page
c6664afe9d fix(parser): Track the most explicit value source
We were only tracking the last value source (default, env, cli, etc).
This works for args because they only come from one source.  Groups
however can come from multiple sources and this was making us treat a
group with a default value as being completely from defaults despite
some values maybe being from the commandline.

We now track the highest precedence value for a group.

Fixes #3330
2022-01-24 10:34:41 -06:00
Ed Page
38e6952d46 fix: Don't panic when propagating
I thought I was adding a test in #3305.  Maybe I considered the
clap_complete changes sufficient for this.  Doing more `debug_assert`s
would be good also.

Unsetting `PropagateVersion` helps in some cases but we need to unset it
globally to override the global propagation.

Fixes #3310
2022-01-18 14:38:58 -06:00
Ed Page
3326a11be0 fix(derive): Don't assume use clap::ArgEnum
The error was when doing `#[clap(arg_enum, default_value_t = ...)]`.

Good example of why we should minimize `use`, at least in tests
(besides reducing merge conflicts, code churn, etc).
2022-01-10 15:41:58 -06:00
Ed Page
e9f6ef6638 fix(parser): Fix more panic quotes 2022-01-04 16:10:26 -06:00
Noa
ffd991f0ae
chore: Fix clap_derive license headers 2022-01-04 14:25:48 -06:00
Ed Page
fa5daf4039
Merge pull request #3250 from epage/hyphen
fix(parser): Ignore Last when checking Hyphen Values
2022-01-04 09:46:59 -06:00
Daniel Eades
d6351a7cf3 style: remove 'from_string' call from 'format' args 2022-01-04 09:20:14 -06:00
Daniel Eades
7f71d642cd style: prefer 'char' to 'str' for single character patterns 2022-01-04 09:20:08 -06:00
Ed Page
15704dcaff fix(parser): Ignore Last when checking Hyphe Values
This was found with #3249
2022-01-04 09:16:03 -06:00
Ed Page
6b9ae5404c fix(derive): Don't enit warnings
We missed covering `Args` warnings when using struct variants.

Fixes #3245
2022-01-03 11:35:34 -06:00
Ed Page
e5fbdc9b95 Revert "Remove {n} support"
This reverts commit 333b993481.

PR #1810's motivation was effectively "this is redundant with `\n`".
That is a fine motivation.  Unfortunately, we don't have a way to force
a hard break in `clap_derive`.  #2389 should help with this eventually
but we shouldn't hold up 3.0 to get that ready.  So in the mean time, we
are restoring `{n}`.

We have #3230 for tracking the re-removal of it.
2021-12-30 11:44:45 -06:00
Ed Page
771a44bcef fix: Remove overriden occurrences as we go
This allows two overriding args to interact with each other mid-line.
This was broken in 7673dfc / #1154.  Before that, we duplicated the override
logic in several places.

Now we plug into the start of a new arg which allows us to do this
incrementally without making the logic complex or inefficient, thanks to
prior refactors.

Fixes #3217
2021-12-27 15:32:37 -06:00
Ed Page
9c6c0174d2 test: Show more detailed failures 2021-12-27 13:57:38 -06:00
Ed Page
bfc486501a test: Panic, rather than exit, on error
Working on a fix for #3217 and can't see what is failing because the
test process exits.
2021-12-27 12:56:15 -06:00
Ed Page
3db09f4dd4 fix: Don't panic on lack of conflicts
Fixes #3197
2021-12-23 13:38:23 -06:00
Ed Page
2e73be43f1 fix: Ensure we validate required-unless
Found this when digging into #3197
2021-12-21 20:41:17 -06:00
Ed Page
318b7859dc fix(help): Don't infer long help from subcommands
Fixes #3193
2021-12-17 09:25:00 -06:00
Ed Page
8924dd7a1e feat(derive): Don't require Display for default ArgEnum
While I'm unsure how much type specialization we should do, we
intentionally have the `arg_enum` attribute for doing special behavior
based on it, so let's take advantage of it.

Fixes #3185
2021-12-16 09:11:32 -06:00
Ed Page
9e64387ef0 revert(help): Partial revert of 3c049b4
The extra whitespace was targeted at machine processing for a subset of
users for a subset of runs of CLIs.  On the other hand, there is a lot
of concern over the extra verbose output.

A user can set the help template for man, if desired.  They can even do
something (env? feature flag?) to make it only run when doing man
generation.  We also have #3174 in the works.

So let's focus on the end-user reading `--help`.  People wanting to use
`help2man` have workarounds to do what they need.

Fixes #3096
2021-12-15 10:36:59 -06:00
Ed Page
d55f040bbd fix(derive): Set both about/long_about with doc comments
The main care about is that when we override a `flatten` / `subcommand`
doc comment in a parent container, that we make sure we take nothing
from the child container, rather than implicitly taking one `about` ut
not `long_about`.

To do this, and to play the most safe with long help detection, we reset
`long_about` to default when there is no doc comment body to use for
`long_about`.

Fixes #2983
2021-12-14 11:07:57 -06:00
Ed Page
1811f5e7af test(derive): Show current doc comment behavior
Based on #2983
2021-12-14 11:07:54 -06:00
Ed Page
7c10b5a9b4 fix(derive): Treat default_value_os like default_value
The test went from panicing to not-panicing

Fixes #3031
2021-12-13 16:25:49 -06:00
Ed Page
19ed78c64f fix(help): Don't commit to '--help' that doesn't work
We have two ways of fixing this
- Making `--help` work
- Don't put `--help` in the help output

For now, I went with the latter.  I tried to make it clear what the
actual requirement is so we can pivot if needed.

Fixes #2892

This happens to also fix the interaction of `DisableHelpFlag` with the
help subcommand and complcations.  I've added a test to help catch if we
break this by changing how we fixed the original issue.

Fixes #2724

These issues were reported against clap3.  I've not tried to reproduce
these in clap2 to see if they should show up in the release notes.
2021-12-13 15:59:14 -06:00
Ed Page
a72e5726f8 fix(error): Ensure newline on value_of_t not found
Found this when auditing for cases related to #2787.
2021-12-13 13:30:32 -06:00
Ed Page
4c8caa6eb3 test(error): Add explicit value_of_t test case
This adds an explicit test case for
221c18bdec when before we covered it via
the example tests.
2021-12-13 13:30:28 -06:00
Ed Page
2eb69def4e fix(error): Ensure trailing newline without help
Fixes #2787
2021-12-13 13:09:48 -06:00
Ed Page
be223df828 fix(ci): Correct release lints
I'm assuming we won't have a negative performance impact by removing
`impl Copy for Id` because the compiler would inline the `clone()`s and
turn them into copies.

Addresses problems from #3164
2021-12-13 09:41:22 -06:00
Richard Maw
e3d355fa85 feat: Make Multicall just strip dir from argv0 2021-12-12 22:08:25 +00:00
rhysd
8ce56d416e fix: Update tests for assertion messages 2021-12-11 20:33:23 +09:00
Ed Page
703238f155 test(derive): Check all derives
There will always be some kind of corner case not covered as code
evolves but this expands the test to all of the basics.
2021-12-10 10:52:30 -06:00
Ed Page
71a564de88 test(derive): Don't parse the actual command line 2021-12-10 10:36:45 -06:00
Frankie Foston
1285c0f885 fix: unqualified result types causing compilation failures with derive implementations 2021-12-10 14:13:26 +00:00
Ed Page
1f465b57e3
Merge pull request #3104 from epage/unstable
test: Actually allow unstable examples to be tested
2021-12-08 21:21:12 -06:00
Ed Page
130a1dc0e2 test: Actually allow unstable examples to be tested 2021-12-08 21:06:51 -06:00
Ed Page
e98253dd4a fix: Rename 'doc' feature
This is prep for potentially other 'doc' changes
2021-12-08 20:10:47 -06:00
Ed Page
ea6829b08e chore(ci): Lint small feature sets 2021-12-07 21:18:35 -06:00
Ed Page
4a5d52350e docs: Update old repo location 2021-12-07 08:14:41 -06:00
Ed Page
6ea893db2c fix: Limit when ui tests run 2021-12-06 12:37:49 -06:00
Ed Page
b2836c07a7 fix: Gracefully handle empty authors 2021-12-06 11:30:26 -06:00
Ed Page
f517c0ede1 docs: Remove author fields 2021-12-06 11:24:23 -06:00
Ed Page
888c27048d docs: Update changelog 2021-12-02 20:26:21 -06:00
Ed Page
500def4904 fix(derive): Smooth out transition for structopt
Adding in a `StructOpt` derive with `structopt` attributes, with
deprecation notices.  Unofrtunately, not as many deprecation warnings as
I would like.  Apparently, you can't do them for a `use` of a derive?  I
also wanted to inject code that would trigger a deprecation notice for
attributes but that would require enough of a refactor that I didn't
consider it worth it.  We are at least providing a transition window
even if it means we'll have to remvoe it next major release without a
deprecation warning.
2021-12-02 20:18:33 -06:00
Ed Page
3f9da04744 fix: Revert as much yaml policy to v2 as possible 2021-12-02 16:06:21 -06:00
Ed Page
0d1f34b91d fix: Finish reverting clap_app 2021-12-02 10:45:10 -06:00