Commit graph

974 commits

Author SHA1 Message Date
Ed Page
10bb9abb1a fix(assert): Reference help_expected 2022-06-08 12:06:15 -05:00
Ed Page
dffd7932b3 fix(assert): Check for version if user specifies ArgAction::Version 2022-06-08 11:59:49 -05:00
Ed Page
9e38353442 fix(derive): Clarify ArgEnum as ValueEnum
We aren't enumerating arguments but values for an argument, so the name
should reflect that.

This will be important as part of #1807 when we have more specific
attribute names.
2022-06-08 11:14:09 -05:00
Ed Page
11d93141dd test(derive): Update snapshots 2022-06-08 09:56:57 -05:00
Ed Page
14a62e11fd fix(parser): Deprecate multiple_occurrences
Fixes #3772
2022-06-08 09:54:23 -05:00
Ed Page
55a705c447 test: Ensure we don't break compatibility 2022-06-07 16:21:37 -05:00
Ed Page
4a9c4dee64 refactor(test): Make it easier to fork tests 2022-06-07 16:21:12 -05:00
Ed Page
86a162d1bb fix(parser): Deprecate occurrences_of
This mostly exist for
- Knowing of the value came from the command-line but we now have
  `ArgMatches::source`
- Counting the number of flags but we now have `ArgAction::Count`
2022-06-07 13:30:32 -05:00
Ed Page
f0cc8b8d25 test: Improve failure output 2022-06-07 13:20:25 -05:00
Ed Page
1428785677 fix(parser): Deprecate args_override_self
This shouldn't be needed anymore now that this is effectively the new
behavior for the non-deprecated actions.

This was briefly talked about in
https://github.com/clap-rs/clap/discussions/2627 but I wasn't familiar
enough with the implementation to know how safe it is.  Now, maintainrs
and users can be more confident because they are explicitly opting into
it.

See also #3795
2022-06-06 14:57:24 -05:00
Ed Page
a979cf9bb8 fix(parser): Deprecate max_occurrences 2022-06-06 14:09:24 -05:00
Ed Page
1879826b21 fix(parser): Deprecate StoreValue / IncOccurrences Actions
Dropping these will help simplify a lot, including removing of
occurrences.

These come at the cost of the derive not yet supporting types that impl
`From`.
2022-06-06 13:41:27 -05:00
Ed Page
647896d929 feat(derive): Expose control over Actions
This is the derive support for #3774 (see also #3775, #3777)

This combined with `value_parser` replaces `parser`.  The main
frustration with this is that `ArgAction::Count` (the replacement for
`parse(from_occurrences)` must be a `u64`.  We could come up with a
magic attribute that is meant to be the value parser's parsed type.  We
could then use `TryFrom` to convert the parsed type to the user's type
to allow more.  That is an exercise for the future.  Alternatively, we
have #3792.

Prep for this included
- #3782
- #3783
- #3786
- #3789
- #3793
2022-06-06 11:35:07 -05:00
Ed Page
0f1de7303d fix(validator): Ignore defaults for requireds
This is a follow up to #3420.  Its easy to overlook this because it is only
useful for the conditionals (we actually prevent applying unconditional
defaults to unconditional requireds).  This became apparent with the
increased use of defaults with `SetTrue`.

As always, there is the question of when is a bug fix a breaking change.
I'm going to consider this safe since we prevent some instances of this
from even happening and we already did #3420 and this is in line with
those.
2022-06-06 11:07:04 -05:00
Ed Page
002204a122 test(derive): Update ui tests 2022-06-04 13:24:46 -05:00
Ed Page
9638f33d2f fix(parser): Exclusive shouldnt preclude defaults
Unsure why a comment said this doesn't matter.  It matters both for
counting arguments and for reporting the correct argument is exclusive.
2022-06-04 12:58:53 -05:00
Ed Page
a971346004 test(parser): Verify indices of defaults
I thought I had broken this but it always seemed to have worked this way
2022-06-04 12:58:53 -05:00
Ed Page
b09def1ad0 test(derive): Verify doc comments on ArgEnum 2022-06-04 12:58:53 -05:00
Ed Page
11fbe7e54b test(derive): Improve help output assertions 2022-06-04 12:58:53 -05:00
Ed Page
52e2874c03 fix(builder): Make it easier to discover/access ArgAction 2022-06-04 12:58:53 -05:00
Ed Page
34368419c2 refactor(bench): Pull out benchmarks into own crate
This is mostly about avoiding criterion's build times when just
developing clap itself.

I'm assuming the derive test changed because criterion's clap v2 isn't
in the dependency tree anymore.
2022-06-03 13:51:26 -05:00
Ed Page
e4b443d8bb fix(parser): Provide default value for Actions
Actions were inspired by Python and Python does not implicitly default
any field when an action is given.  From a Builder API perspective, this
seemed fine because we tend to focus the Builder API on giving the user
all information so they can make their own decisions.  When working on
the Derive API, this became a problem because users were going to have
to migrate from an implied default to an explicit default when a common
default is good enough most of the time.  This shouldn't interfere with
Builder users getting more details when needed.

This also highlighted two problems
- We set the index for defaults
- We don't debug_assert when applying conditional requirements with a
  default present
2022-06-03 10:02:35 -05:00
Ed Page
5db611384e test(derive): Ensure we don't break compatibility 2022-06-02 16:56:14 -05:00
Ed Page
002d4421e5 Revert "fix(parser): Don't treat missing values as missing args"
This reverts commit 50f4018dcf.

This broke compatibility with the derive when dealing with
`Option<Option<T>>` and related cases.
2022-06-02 16:56:14 -05:00
Ed Page
552e6feb3f fix(derive): Adjust precedence for flag/occurrence logic 2022-06-02 16:56:12 -05:00
Ed Page
cccc88bcc2 fix(derive): Fix typo in error messages 2022-06-02 16:46:50 -05:00
Ed Page
773ba94c4e refactor(derive): Merge handling of bool/from_flag
This will make it easier to divide off parser logic for adding in
actions.

This does mean we can't provide error reporting on bad values with
`bool` but
- We should have also been doing that for `from_flag`
- We'll be dropping this soon in clap4 anyways
2022-06-02 13:01:59 -05:00
Ed Page
dfc55cd6e3 test(derive): Update ui test to be correct otherwise 2022-06-02 11:59:09 -05:00
Ed Page
50f4018dcf fix(parser): Don't treat missing values as missing args 2022-06-02 13:45:18 -05:00
Ed Page
95c812b411 feat(builder): Set/Append Actions
This round out the new style actions and allow us to start deprecating
occurrences.

As part of an effort to unify code paths, this does change flag parsing
to do splits.  This will only be a problem if the user enables splits
but we'll at least not crash.  Once we also address #3776, we'll be able
to have envs all work the same.
2022-06-01 10:12:44 -05:00
Ed Page
c58a802a1d style: Make clippy happy 2022-06-01 06:45:23 -05:00
Ed Page
2e9e556359 test(parser): Ensure conditional requirements work with new Actions 2022-05-31 21:21:50 -05:00
Ed Page
4afd1aafe5 fix(parser): Don't double-increment index on flags 2022-05-31 21:21:50 -05:00
Ed Page
06ea572770 fix(parser): Apply conditional defaults
Now that we can store constants for flags, we can apply defaults for
flags too.

Fixes #3294
2022-05-31 21:21:50 -05:00
Ed Page
70b633b0ea refactor(parser): Be explicit about not not iterating over every value 2022-05-31 14:44:36 -05:00
Ed Page
5a55f4a863 fix(parser): Restore positional occurrence behavior
This fixes a compatibility issue introduced in 9805fdad1b
2022-05-31 14:44:36 -05:00
Ed Page
cb6f7b783a fix(parser): Restore interleaved positional behavior
If we felt this was important long-term, we should fix this outside of
the Action.  Since we might be changing up occurrences (#3772), we can
probably get away with a hack.
2022-05-31 14:15:57 -05:00
Ed Page
f2a219e77d refactor(parser)!: Switch flag values to Actions
This changes how occurrences and values are grouped for multiple values.
Today, it appears as a bug.  If we move forward with #3772, then this
can make sense.
2022-05-31 14:04:12 -05:00
Ed Page
bba83cb2af test(parser): Verify interleaved group behavior 2022-05-31 14:00:48 -05:00
Ed Page
c72f03e53f refactor(parser): Be more explicit in default_missing_values
I wrote these tests expecting to highlight a bug but it turns out things
were structured just right to not exhibit it.  The fact that the code
looks like its broken is a problem, so I restructured it (put it first,
changed the source) so it doesn't look suspicious anymore.
2022-05-27 07:04:24 -05:00
Ed Page
302bf63678 fix(parser): Always use delimiter on defaults/env
Doesn't make sense to respect how the command line ended
2022-05-26 20:50:44 -05:00
Ed Page
ccc809a9df fix(parser): Allow delimiting default_missing_values
Fixes #3761
2022-05-26 20:36:49 -05:00
Ed Page
9805fdad1b refactor(parser)!: Consolidate group/occurrence logic
We were independently starting occurrences and starting value groups.
Now we do them at the same time.

COMPATIBILITY: This changes us from counting occurrences per positional
when using `multiple_values` to one occurrence.  This is user visible
and tests were written against it but it goes against the documentation
and doesn't quite make sense.
2022-05-26 19:30:29 -05:00
Ed Page
f082f499ea fix: Remove deprecation warning 2022-05-26 15:52:35 -05:00
Ed Page
ae97550638 fix(validator): Deprecate validator_regex
Fixes #3743
2022-05-25 14:32:00 -05:00
Ed Page
408ca3c5d7 test(derive): Update for deprecations 2022-05-25 13:13:22 -05:00
Ed Page
a712adefcd fix(parser): Deprecate value_of and friends 2022-05-25 12:57:11 -05:00
Ed Page
256643f8d3 fix: Deprecate possible_values 2022-05-25 12:57:11 -05:00
Ed Page
573d496bc6 fix: Deprecate forbid_empty_values 2022-05-25 12:57:11 -05:00
Ed Page
177511dab1 fix: Deprecate validator / validator_os
`validator_regex` is being ignored for now as I await on a comment
period for #3743
2022-05-25 12:57:11 -05:00
Ed Page
f15a1aab1a fix: Deprecate allow_invalid_utf8 2022-05-25 12:57:11 -05:00
Ed Page
15616bbd13 fix(error): Remove usage from value validation
When to show usage?  We are currently mixed about it.  For `validator`,
we didn't show it at all.  Sometimes we show the used arguments and
sometimes we don't.

With `ValueParser`, I ran into the problem that we weren't showing the
used arguments like we had previously in some cases.  In deciding how to
solve this, I went with the simplest route for now and removed it as the
usage likely doesn't add much context to help people solve their
problem, more so the recommendation for help.  We'll see how the
feedback is on this and adjust.
2022-05-23 20:56:04 -05:00
Ed Page
a35df14caf feat(derive): Opt-in to inferred value_parser 2022-05-20 19:25:20 -05:00
Ed Page
b52c7f115e feat(derive): Allow users to opt-in to ValueParser
For clap 3, its opt-in as a precaution against breaking
compatibility in some weird cases.

This does require the types to implement `Clone`.

Fixes #3734
Fixes #3496
Fixes #3589
2022-05-20 15:38:44 -05:00
Ed Page
e0e7383300 test: Re-enable ui tests
`derive_ui.rs` did not have a marker for needing to be updated on MSRV
changes, so it got missed.
2022-05-20 14:10:32 -05:00
Ed Page
686b0379ce feat(multicall): Stablize multicall
`multicall` allows you to have one binary expose itself as multiple
programs, like busybox does.  This also works well for user clap for
parsing REPLs.

Fixes #2861
2022-05-20 12:20:40 -05:00
Ed Page
1a2b7acd60 test(multicall): Conditionalize suggestion-related case
This impacts the error code (#3676) and the error body and without
suggestions, its redundant.
2022-05-20 12:20:40 -05:00
Ed Page
d826ab9445 fix(derive): Move args to new 'get_one'/'get_many' API 2022-05-16 15:16:51 -05:00
Ed Page
dcf69d1c87 refactor(parser): Track str/OsStr values via Box
Unfortunately, we can't track using a `ValueParser` inside of `Command`
because its `PartialEq`.  We'll have to wait until a breaking change to
relax that.

Compatibility:
- We now assert on using the wrong method to look up defaults.  This
  shouldn't be a breaking change as it'll assert when getting a real
  value.
- `values_of`, et al delay panicing on the wrong lookup until the
  iterator is being processed.
2022-05-12 16:13:30 -05:00
Ed Page
17c99d2878 test(derive): Unsure why this is failing 2022-05-12 06:23:38 -05:00
Ed Page
2e3540355a fix(derive): Don't change case of Arg id's (unstable)
This will make it easier to reference arguments with different
attributes.

Fixes #3282
2022-05-09 10:36:03 -05:00
Ed Page
f7e4dd23d6 refactor(derive): Divide rename_all assertions 2022-05-06 16:47:52 -05:00
Ed Page
ddc9d54f41 refactor(derive): Generalize test name 2022-05-06 16:45:03 -05:00
Ed Page
fe4888d668 refactor(derive): Group subcommand rename tests 2022-05-06 16:43:23 -05:00
Ed Page
65538e21a8 fix(derive): Detect escaped ambiguous subcommands (unstable) 2022-05-06 15:46:34 -05:00
Ed Page
20ff4ce05a doc(parser): Document external subcommand escaping behavior 2022-05-06 12:38:23 -05:00
Ed Page
03f132129b fix(parser): Always put in arg "" for external subcommands (unstable)
This allows distinguishing external subcommands from built-in
subcommands which can especially be confusing when escaping subcommands.

Fixes #3263
2022-05-06 12:25:20 -05:00
Liu Dingming
1b63fbd6df feat(derive): Start unstable-v4 feature flag
This is split out of #3661 as several changes I'm working on need it.
2022-05-06 14:56:55 -05:00
Ed Page
089f96eb87 fix(help): Disallow too many value names (unstable)
I can't think of a case for this or a way to render it.

Fixes #2695
2022-05-06 13:54:07 -05:00
Ed Page
70c29e3dd8 fix(help): Use '...' when not enough value names supplied 2022-05-06 13:33:17 -05:00
Evgeniy Terekhin
229b44d9bb
fix(macros): Allow dashed values (#3699)
add support for dashed arg names and values in arg! macro
2022-05-06 10:58:00 -05:00
Ed Page
e23c786f62 refactor(help): Remove redundant required check
With us moving the required de-duplication up a level, it made this
check redundant.  By removing this check, we're more likely to have an
item in the `incls` which forces a smart usage and reduces the chance of
an `[ARGS]` or `[OPTIONS]`, so a couple of tests changed.
2022-05-05 17:02:49 -05:00
Ed Page
dedbabd402 fix(error): Don't duplicate args in usage
Gave up trying to decipher the existing logic for safe ways to
de-duplicate manually and switched to an `IndexSet` to enforce only one
of each argument exists.

Fixes #3556
2022-05-04 11:05:37 -05:00
Ed Page
16791ab0a7 test(help): Update for display name change 2022-05-04 20:46:49 -05:00
Ed Page
c7ff695581 fix(help): Don't wrap URLs
Confusingly, there are two similar but slightly different settings in
`textwrap`.  We need both set.

Fixes #3222
2022-05-04 16:00:08 -05:00
Ed Page
d3e36b1c90 fix(v4): Disallow leading dashes in long's
This is a step towards #3309.  We want to make longs and long aliases
more consistent in how they handle leading dashes.  There is more
flexibility offered in not stripping and it matches the v3 short
behavior of only taking the non-dash form.  This starts the process by
disallowing it completely so people will catch problems with it and
remove their existing leading dashes.  In a subsequent breaking release
we can remove the debug assert and allow triple-leading dashes.
2022-05-04 15:38:08 -05:00
Ed Page
61b8bbd218 fix(parser): Exclusive overrides required
`Arg::exclusive` is just another way of defining conflicts, so a
present-exclusive arg should override required like other conflicts.

Instead of going through the message of enumerating all other arguments
as exclusive, I shortcutted it and special case exclusive in the
required check like we do with conflicts.  The big downside is the
implicit coupling between the code paths rather than having a consistent
abstraction for covering conflicts.

This isn't a breaking change because if someone defined an exclusive arg
as a sibling to a required arg, the exclusive arg could never be used,
it always errored, and so no valid application can be written with it.

Fixes #3595
2022-05-04 12:25:44 -05:00
Ed Page
3cfea3223b fix(help): Offer a html_template variable for display name
This is a step towards #992.  When help renders the application name, it
uses the `bin` template variable which is just the `bin` name with
spaces converted to ` `.  While having `app.exe sub` makes sense,
`app.exe-sub` does not.

To get around needing this for usage, we've created a `display_name`
field that is fairly similar but
- The root name is the `name` and not `bin_name`
- We always join with `-`

This means that the derived `bin_name` will only show up in usage.

For now, the default template has not been updated as that is a minor
compatibility change and should be in a minor release, at least.  I was
worried this would be a full breaking change.  The main case I was
worried about was cargo subcommands but our tests show they should just
work.
2022-05-03 14:34:47 -05:00
Ed Page
af3b789e4c fix(multicall): Consistently skip multicall bin in help 2022-05-02 11:50:30 -05:00
Ed Page
8cd59fa4e5 fix(multicall): More consistent whitespace in errors 2022-05-02 11:01:14 -05:00
Ed Page
f9fdb99ee8 fix(multicall): Disallow args on multicall binary
Set expectations for how this can be used and to make sure the right
errors are given.
2022-05-02 09:33:09 -05:00
Ed Page
ce727f1951 fix(error): Render actual usage for unrecognized subcommands
For some reason this code path diverged and manually constructed a
usage, not following any of our patterns for doing so.
2022-05-02 09:25:44 -05:00
Ed Page
5cd1a4070b fix(multicall): Show subcommands are required 2022-05-02 09:13:44 -05:00
Ed Page
414ae57a2a fix(multicall): Improve bad multicall binary error
By removing all arguments, we've switched from an "unrecognized
argument" error to a "unrecognized subcommand" error.  While the wording
has room for improvement, its at least progress on #2862.
2022-05-02 09:12:12 -05:00
Ed Page
ff53b087e0 chore: Remove dead code 2022-05-02 05:52:18 -05:00
Ed Page
0ecb6f4869 fix(builder): Fully recurse when building
Besides addressing the panic from assuming things were built when they
weren't, this should fix some completion issues for some people.

Fixes #3669
2022-04-30 20:02:06 -05:00
Ed Page
ccf8634c19 fix(help): Provide correct context for help subcmd errors 2022-04-29 20:25:05 -05:00
Ed Page
1452c1e42b fix(help): Help subcommands usage includes requires arguments 2022-04-29 20:16:19 -05:00
Ed Page
37ebb71806 fix(help): write_help usage includes required arguments 2022-04-29 20:15:54 -05:00
Ed Page
2edc1a2bdf test(help): Verify showing of required attributes 2022-04-29 15:46:15 -05:00
Ed Page
7cdce9cabe refactor(test): Use snapbox's diffs 2022-04-29 15:32:25 -05:00
Ed Page
1e2471649e test(output): Ensure correct streams
This is to prevent #3648 from happening again
2022-04-22 10:56:47 -05:00
Ed Page
e7471eb546 test(group): Verify overrides required
This adds a test for de89c050c9 that
confirms #3647 is fixed

Fixes #3647
2022-04-22 07:01:53 -05:00
Ed Page
a484f622de fix(validate): Overrides always ignore required
Before, if two arguments were required *and* overrode each other, then
`cmd --opt=1 --other=2` succeded but `cmd --other=2` failed despite
ignoring `--opt=1`.  Requiring `--opt=1` to be present but unavailable
doesn't help anyone and makes the behavior less predictable.

Now both commands will have the same behavior.
2022-04-21 15:23:05 -05:00
Ed Page
8f182067e3 feat(clap): Publicly expose Command::build
`Command::_build_all` started as an internal function for
`clap_complete` as a stopgap until #2911.  Overtime, we've been finding
more cases where this function needs to be called, so now we're going to
fully embrace it until #2911 so people aren't scrared off by the hidden
implementation from using it.

This was inspired by #3602

Comptibility: Though this adds a deprecation which we general reserve
for minor or major versions, this is enough of a corner case that I'm
fine doing this in a patch release.
2022-04-19 10:13:43 -05:00
shir0kamii
fb4755d1c3 feat(derive): Don't abort when non-unit variant is skipped 2022-03-31 18:49:21 +02:00
shir0kamii
ee3d12ec56 fix(derive): Abort on non-unit variant 2022-03-30 03:49:14 +02:00
plaflamme
154c0d0c65
test: Add test to demonstrate regression 2022-03-06 23:09:55 -05:00
Roland Fredenhagen
33949ce4de
feat(help): Show PossibleValue help in --help (#3503)
`-h` (short help) still shows the same.

This gates it behind an `unstable-v4` feature flag to avoid disrupting users who set the help without knowing where all it shows up (particularly derive users where `ArgEnum` is automatically extracting the help).

Fixes #3312
2022-03-02 09:15:28 -06:00
Ed Page
3f2a37088b fix(assert): Validate delimited defaults
Fixes #3514
2022-02-28 09:21:44 -06:00
Ed Page
cb937641fa fix(derive): Allow other attributes with subcommand that has subcommands
This was overlooked when we added support for `#[clap(subcommand)]` to
variants.

Fixes #3504
2022-02-23 09:23:33 -06:00
Ed Page
976f3d500a
Merge pull request #3473 from epage/derive
fix: Change `IntoApp::into_app` to `CommandFactory::command`
2022-02-15 09:33:44 -06:00
Ed Page
360c4d6b8a docs: Update to new command! macro 2022-02-15 08:54:59 -06:00
Ed Page
65b9c88b3c fix: Update app_from_crate for App rename
Instead of just renaming it, I reconsidered what the API should look
like.  A custom separator for author does not make sense positionally
but accepting a name, and defaulting it, does fit with what someone
would expect.

I removed the `_from_crate` suffix because it doesn't seem necessary.
We don't have this kind of naming for the derive.  I feel it cleans
things up this way.
2022-02-15 08:39:07 -06:00
Ed Page
ddac492302 fix: Rename IntoApp to CommandFactory
This is part of the `App` rename.

Previously, I was concerned about not being able to deprecate

For backwards compatibility, we still expose the `IntoApp` name.
2022-02-15 08:24:00 -06:00
Ed Page
7aa45667f5
Merge pull request #3472 from epage/cmd
fix: Rename App to Command
2022-02-15 07:55:36 -06:00
Maarten de Vries
bd68653248 test: Add UI test for unsupported parsers 2022-02-15 12:00:25 +01:00
Ed Page
3475555de6 fix(help): Use standard alternate syntax for subcommands 2022-02-14 21:18:33 -06:00
Ed Page
c3fec1fa75 fix: Update derive->Command function name
No good solution for transitioning the trate name, unfortnately, since
we can't mark `use`s as deprecated (we can, it just does nothing).

I got rid of the `into` prefix because that implies a `self` parameter
that doesn't exist.
2022-02-14 16:04:10 -06:00
Ed Page
e8010e79a9 refactor: Update app variables to cmd 2022-02-14 15:55:56 -06:00
Ed Page
c4144d7d6c docs: Update App references to Command 2022-02-14 15:33:49 -06:00
Pavan Kumar Sunkara
24b86d18d0 test: Remove unnecessary feature usage in tests 2022-02-13 19:00:29 +00:00
Ed Page
4895a32e81 fix: Deprecate SubcommandRequiredElseHelp
Now that we can use `SubcommandRequired |
ArgRequiredElseHelp`, this setting offers little value but requires we
track required subcommands with two different settings.  Deprecating as
the cost is not worth the benefit anymore.

Issue #3280 will see the derive updated
2022-02-11 15:31:25 -06:00
Ed Page
e8e469178c fix(validate): Give precedence to ArgRequiredElseHelp 2022-02-11 14:59:52 -06:00
Ed Page
d3f5d7ce34 fix: Clarify Arg/ArgGroup id's role
This adjusts names.  Adjusting the derive naming (and re-naming) is left
to #2475.

Fixes #3335
2022-02-11 14:11:50 -06:00
Ed Page
06d43a02da fix(help): Subcommand help looks like --help
Like was said in #2435, this is what people would expect.

While we should note this in a compatibility section in the changelog, I
do not consider this a breaking change since we should be free to adjust
the help output as needed.  We are cautious when people might build up
their own content around it (like #3312) but apps should already handle
this with `--help` so this shouldn't be a major change.

We aren't offering a way for people to disable this, assuming people
won't need to.  Longer term, we are looking at support "Actions" (#3405)
and expect those to help customize the flags.  We'll need something
similar for the `help` subcommand.

Fixes #3440
2022-02-11 12:47:34 -06:00
Ed Page
272f840178 feat: Replace core set of AppSettings with functions
This is a part of #2717

Some settings didn't get getters because
- They are transient parse settings (e.g. ignore errors)
- They get propagated to args and should be checked there

`is_allow_hyphen_values_set` is a curious case.  In some cases, we only
check the app and not an arg.  This seems suspicious.
2022-02-11 12:35:09 -06:00
Ed Page
9bd7060089 fix: Deprecate various APIs
- ArgSettings are part of #2717
- Errors are part of #2628
- `help_heading` is part of #1807 and #1553
- Some misc parts are for API consistency
2022-02-10 19:37:47 -06:00
Ed Page
47d76742eb feat: Add Arg getters for all settings
This is prep for #2717
2022-02-10 10:18:41 -06:00
Ed Page
81092b5aed fix: Detect deeply recursed global args
Fixes #3428
2022-02-09 16:05:27 -06:00
Ed Page
6c60b79d21 fix(assert): Provide next steps for '-h' conflicts
For now, we are going to provide a better debug assert in this case.
Resolving #3405 is the better long term route.

Fixes #3403
2022-02-08 18:56:14 -06:00
Ed Page
0aabcd70c1 test: Ensure we can avoid a short on help 2022-02-08 18:51:51 -06:00
Ed Page
9f41bb3948 fix(assert): Report invalid defaults in debug asserts
This can help people catch them via `App::debug_assert` rather than
waiting until the default is used and validated.

Fixes #3202
2022-02-08 14:41:33 -06:00
Ed Page
b2d1ebef4b fix(help): ArgsRequiredElseHelp should ignore defaults
Fixes #1264
2022-02-08 12:34:19 -06:00
Ed Page
d3b084926a test(validate): Ensure defaults are ignored 2022-02-08 12:27:40 -06:00
Ed Page
6ad52f41b3 feat: Allow disabling derive display order
In clap 4.0, we will make `DeriveDisplayOrder` the default and this is
how you'll disable it.

This is part of #2808
2022-02-07 19:19:11 -06:00
Ed Page
5290f82133 feat: Override DeriveDisplayOrder behavior with App::next_display_order
For the derive API, you can only call `next_display_order` when dealing
with a flatten.  Until we offer app attributes on arguments, the user can workaround with
this no-op flattens.

This is a part of #1807
2022-02-07 19:19:11 -06:00
Ed Page
c00f71ec4a feat: Add App::next_help_heading
This clarifies the intent and prepares for other functions doing the
same, like `next_display_order`.  This will then open us to name
`subcommand_help_heading` and `display_order` similar.

The deprecation is waiting on 3.1.

This is part of #1807 and #1553.
2022-02-07 19:19:01 -06:00
Ed Page
7497dbb6cc feat(error: Expose value-validation context 2022-02-04 14:35:52 -06:00
Ed Page
5095e5c992 feat(error: Expose unrecognized-subcommand context 2022-02-04 11:15:22 -06:00
Ed Page
b538a43961 refactor(error): Switch to error::ErrorKind 2022-02-02 15:41:24 -06:00
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