Commit graph

913 commits

Author SHA1 Message Date
Ed Page
16b0362807 fix(error):! Merge EmptyValue into InvalidValue
There isn't a reason to programmatically differentiate them so this
merges them simplify programamtic cases and to hopefully reduce binary
size.
2022-07-22 09:06:01 -05:00
Ed Page
1281e78dc0 test: Limp along 2022-07-21 17:08:35 -05:00
Ed Page
cf60f84894 fix!: Remove ArgSettings from the API 2022-07-21 16:17:44 -05:00
Ed Page
09c6405d5c fix!: Remove validator 2022-07-21 16:05:39 -05:00
Ed Page
d7618c79af fix!: Remove args_override_self 2022-07-21 15:45:12 -05:00
Ed Page
cd9cbb4c20 fix!: Remove ArgMatches::*value* functions 2022-07-21 14:24:16 -05:00
Ed Page
7d403fad78 test: Remove legacy cases 2022-07-21 13:38:24 -05:00
Ed Page
819c1e061d fix!: Remove deprecated macros 2022-07-21 13:03:21 -05:00
Ed Page
ff0796b014 fix(derive)!: Remove old derive names 2022-07-21 12:57:12 -05:00
Ed Page
99d92c916c fix!: Remove yaml support 2022-07-21 12:46:47 -05:00
Ed Page
765af4198c fix!: Remove regex validation 2022-07-21 12:42:09 -05:00
Ed Page
48f087d090 fix(parser): low index multiples work with flags
We had some tests for this but not sufficient obviously.  The problem is
we were tweaking the positional argument counter when processing flags
and not just positional arguments.  Delaying it until after flags seems
to fix this.

Fixes #3959
2022-07-20 17:44:49 -05:00
Ed Page
afc540153b
Merge pull request #3902 from tmccombs/get-conflicts-with-group
Include groups in `get_arg_conflicts_with`
2022-07-14 09:37:45 -05:00
Thayne McCombs
f27f1f57ea fix: Include groups in get_arg_conflicts_with
So that it doesn't panic if trying to get the conflicts for an Arg that
conflicts with a group.

Fixes: #3900
2022-07-14 01:08:06 -06:00
Emerson Ford
e39156e0b9 feat: Add method to get non-visible arg aliases 2022-07-12 11:23:22 -07:00
Emerson Ford
8e1411b3b2 fix: Loosen lifetime constraint on mut_subcommand 2022-07-11 19:12:36 -07:00
Emerson Ford
619f209138 feat: Add mut_subcommand method to Command
this allows us modify existing subcommands on an existing/already built
Command struct
2022-06-29 20:42:58 -07:00
Ed Page
72d206e4d9 fix(parser): Ensure globals override env vars
This fixes a bug introduced in 4a694f3592
when we were trying to move away from presence checks via occurrences.
I switched it to the common type of presence check but really what we
want is a highest-precedence check.

Fixes #3872
2022-06-27 22:40:40 -05:00
Ed Page
f082eb6d4a test(parser): Verify global/default interaction 2022-06-27 22:32:13 -05:00
Ed Page
3c4e684c8b test: Verify auto-traits for core types
By checking these types, we'll get some other types for free, like
`Command` verifying `Arg`.

This was inspired by #3876
2022-06-27 20:50:29 -05:00
Stiopa Koltsov
464ef3920b refactor: Put once_cell reexport into __macro_refs
When upgrading our company projects from clap 3.1 to clap 3.2 I had
to fix several references to `clap::lazy_init`. People are not
supposed to do that, but that's hard to enforce.

Hope placing `once_cell` reexport into `__macro_refs` prevent at
least some of the such issues in the future.
2022-06-26 04:13:03 +01:00
omjadas
4d521429be test: Add test for default_value_os_t 2022-06-15 13:46:59 +10:00
Ed Page
7515bfeb51 fix: Allow people to opt-in to deprecations
This adds a new `Cargo.toml` feature named `deprecated` that opts
controls whether deprecation warnings show up.  This is starting off as
non-default though that may change (see below).

Benefits
- Allows a staged rollout so a smaller subset of users see new
  deprecations and can report their experience with them before everyone
  sees them.  For example, this reduces the number of people who have to
  deal with #3822.
- This allows people to defer responding to each new batch of
  deprecations and instead do it at once.  This means we should
  reconsider #3616.

The one risk is people who don't follow blog posts and guides having a
harder time upgrading to the next breaking release without the warnings
on by default.  For these users, we reserve the right to make the
`deprecated` feature `default`.  This is most likely to happen in a
minor release that is released in conjunction with the next major
release (e.g. when releasing 4.0.0, we release a 3.3.0 that enables
deprecations by default).  By using a feature, users can still disable
this if they want.

Thanks @joshtriplett for the idea
2022-06-14 10:50:05 -05:00
Ed Page
0a529c14cc fix(derive): Switch default actions/parsers for unstable-v4 2022-06-13 18:59:58 -05:00
Ed Page
cc76d2881c test(derive): Allow specializing tests for unstable-v4 2022-06-13 17:00:39 -05:00
Ed Page
3686244264 test(derive): No longer supporting some wrapped types
With the new `ArgMatches`, we need to know what the inner type is.

Unfortunately, #3142 didn't list use cases for this.  We dropped the
`Option` alias changing `T` but we still have a `Result` in there that
is aliased.

One potential workaround if people need it is if we add an attribute to
specify the `get_many::<T>` type.  This would also help with
`ArgAction::Count` to support more data types.
2022-06-13 16:56:34 -05:00
Ed Page
b7668e84f5 test: Don't run legacy tests with v4 behavior 2022-06-13 16:47:25 -05:00
Ed Page
483b64ee8e test(derive): Update another case to new approach 2022-06-13 16:45:09 -05:00
Ed Page
9910b1477b fix(derive): Find a better target for validator deprecation warnings
Putting it on the doc comment is weird.  We are now putting it on the
field which is a slight improvement.  This better conveys "this is
auto-generated".

No test was added because the use case that I know of for exposing this
is short lived.
2022-06-13 16:14:05 -05:00
Ed Page
d72b313bf2 test: Match rest of style 2022-06-13 07:48:06 -05:00
Ed Page
c8b45f75b8
Merge pull request #3820 from epage/panic
fix(assert): Tweak bad arg panics
2022-06-13 07:40:05 -05:00
梦想实现家
3eacf5b8b0
fix(builder): Don't double-has arg id in default_value_ifs_os (#3815) 2022-06-13 07:39:50 -05:00
Ed Page
a1320754f9 fix(assert): Be consistent in ID language for args 2022-06-13 07:08:38 -05:00
Ed Page
ca2846615c docs(parser): Encourage people to read the whole deprecation message 2022-06-10 19:41:50 -05:00
Ed Page
9caec5a52d fix(parser): Deprecate ArgMatches::is_present 2022-06-10 14:21:25 -05:00
Ed Page
fce1125ba9 fix(assert): Allow required flags
Newstyle flags have defaults which prevents them from being required
until now.
2022-06-10 10:16:44 -05:00
Ed Page
31b22d1a51 perf(parser): Take up less memory with ArgAction::Count
Someone should not reasonably expect a coun flag to go up to billions,
millions, or even thousands.  255 should be sufficient for anyone,
right?

The original type was selected to be consistent with
`ArgMatches::occurrences_of` but that is also used for tracking how
many values appear which can be large with `xargs`.

I'm still conflicted on what the "right type" is an wish we could
support any numeric type.  When I did a search on github though, every
case was for debug/quiet flags and only supported 2-3 occurrences,
making a `u8` overkill.

This came out of a discussion on #3792
2022-06-09 11:09:38 -05:00
SabrinaJewson
560f0c076a
fix: Appease CI 2022-06-08 20:45:25 +01:00
SabrinaJewson
6e49bf7419
refactor: Make AnyValueParser private 2022-06-08 20:36:55 +01:00
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