Commit graph

2872 commits

Author SHA1 Message Date
Ed Page
50259e51d5 fix!: Remove deprecated ArgActions 2022-07-22 20:07:24 -05:00
Ed Page
122b562e6b fix!: Change default actions to Set/SetTrue
This is in prep for removing StoreValue/IncOccurrences
2022-07-22 20:00:47 -05:00
Ed Page
4b499ac024 docs(env): Fix bool example 2022-07-22 19:51:23 -05:00
Ed Page
0039ef91fa fix: Have arg! collection across flags for positionals 2022-07-22 19:51:23 -05:00
Ed Page
3356e24360 refactor: Move action defaulting to where it belongs 2022-07-22 19:46:07 -05:00
Ed Page
3ca27f0879 refactor: Remove dead code for NoAutoHelp/NoAutoVersion 2022-07-22 19:42:49 -05:00
Ed Page
24735e3a1d fix!: Pull AppSettings out of API
Part of #3021
2022-07-22 16:05:54 -05:00
Ed Page
11076a5c70 fix(help)!: Make DeriveDisplayOrder the default, removing it
Force sorting with `next_display_order(None)`

Fixes #2808
2022-07-22 15:52:03 -05:00
Ed Page
389ff4ff21 fix(help): Subcommand display order respects Command::next_display_order
Previous behavior:
- They'd be sorted by default
- They'd derive display order if `DeriveDisplayOrder` was set
  - This could be set recursively
- The initial display order value for subcommands was 0

New behavior:
- Sorted order is derived by default
- Sorting is turned on by `cmd.next_display_order(None)`
  - This is not recursive, it must be set on each level
- The display order incrementing is mixed with arguments
  - This does make it slightly more difficult to predict
2022-07-22 15:03:16 -05:00
Ed Page
e09a3321af fix!: Ignore required when subcommands conflict with required
Fixes #3940
2022-07-22 14:10:27 -05:00
Ed Page
36dcb05d96 fix!: Change arg! to use ArgAction
Fixes #3795
2022-07-22 13:24:40 -05:00
Ed Page
b77ed545ac fix(env)!: Parse help/version like normal
Fixes #3776
2022-07-22 13:12:12 -05:00
Ed Page
8b064cfee9 fix(derive): Move off of SubcommandRequiredElseHelp
This also let us remove the deprecated attribute

Fixes #3280
2022-07-22 12:33:31 -05:00
Ed Page
50019cacdc
Merge pull request #3967 from epage/parse
fix(derive)!: Remove deprecated parse attribute
2022-07-22 12:27:43 -05:00
Ed Page
7068586246 fix(derive)!: Remove deprecated parse attribute 2022-07-22 12:14:29 -05:00
Ed Page
0d459128d7 fix(error)!: Merge UnrecognizedSubcommand into InvalidSubcommand
Fixes #3676
2022-07-22 12:12:35 -05:00
Ed Page
a842bd64a0 fix!: Use display_name rather than bin_name in version output 2022-07-22 11:40:30 -05:00
Ed Page
01a3ea425f fix!: Remove unstable-v4 feature gate 2022-07-22 11:34:06 -05:00
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
0902ac71f5 docs: Don't link to removed functions 2022-07-21 17:05:57 -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
f10809f0cc fix!: Remove possible_values 2022-07-21 15:54:26 -05:00
Ed Page
d7618c79af fix!: Remove args_override_self 2022-07-21 15:45:12 -05:00
Ed Page
0405966896 fix!: Remove allow_invalid_utf8 2022-07-21 15:32:10 -05:00
Ed Page
0f3e1b17cf fix!: Remove max_occurrences 2022-07-21 15:26:22 -05:00
Ed Page
137924fe48 fix!: Remove forbid_empty_values 2022-07-21 15:24:25 -05:00
Ed Page
6e1e0f9fa2 fix!: Remove App alias for Command 2022-07-21 15:08:37 -05:00
Ed Page
b94d5fcec0 fix!: Remove renamed deprecated functions 2022-07-21 14:57:55 -05:00
Ed Page
bcad76396b fix!: Remove ErrorKind::ArgumentNotFound
This existed for `value_of_t` and isn't needed anymore
2022-07-21 14:42:34 -05:00
Ed Page
75ebeca6d8 fix!: Remove clap 2.x compatibility functions 2022-07-21 14:34:27 -05:00
Ed Page
cd9cbb4c20 fix!: Remove ArgMatches::*value* functions 2022-07-21 14:24:16 -05:00
Ed Page
d4d21b0f7f fix!: Remove WaitOnError 2022-07-21 13:35:49 -05:00
Ed Page
fc7aa40c87 fix!: Remove Error::info and Error::kind fields 2022-07-21 13:06:11 -05:00
Ed Page
819c1e061d fix!: Remove deprecated macros 2022-07-21 13:03:21 -05:00
Ed Page
57bfb8c425 fix!: Remove usage parser 2022-07-21 12:59:56 -05:00
Ed Page
6428618bf2 fix(derive)!: Remove deprecated trait methods 2022-07-21 12:57:17 -05:00
Ed Page
ff0796b014 fix(derive)!: Remove old derive names 2022-07-21 12:57:12 -05:00
Ed Page
da5d5b8b53 fix!: Remove SubCommand 2022-07-21 12:48:52 -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
5e02445ce5 docs: Small tweak to lib docs 2022-07-19 15:54:01 -05:00
Tshepang Mbambo
01d7e7ac04
docs: reduce the need to guess 2022-07-19 22:32:42 +02:00
Ed Page
d43f1dbf6f docs: Move everything to docs.rs
A couple of things happened when preparing to release 3.0
- We needed derive documentation
  - I had liked how serde handled theres
  - I had bad experiences finding things in structopt's documentation
- The examples were broken and we needed tests
- The examples seemed to follow a pattern of having tutorial content and
  cookbook content
- We had been getting bug reports from people looking at master and
  thinking they were looking at what is currently released
- We had gotten feedback to keep down the number of places that
  documentation was located

From this, we went with a mix of docs.rs and github
- We kept the number of content locations at 2 rather than 3 by not
  having an external site like serde
- We rewrote the examples into explicit tutorials and cookbooks to align
  with the 4 styles of documentation
- We could test our examples by running `console` code blocks with
  trycmd
- Documentation was versioned and the README pointed to the last release

This had downsides
- The tutorials didn't have the code inlined
- Users still had a hard time finding and navigating between the
  different forms of documentation
- In practice, we were less likely to cross-link between the different
  types of documentation

Moving to docs.rs would offer a lot of benefits, even if it is only
designed for Rust-reference documentation and isn't good for Rust derive
reference documentation, tutorials, cookbooks, etc.  The big problem was
keeping the examples tested to keep maintenance costs down.  Maybe its
just me but its easy to overlook
- You can pull documentation from a file using `#[doc = "path"]`
- Repeated doc attributes get concatenated rather than first or last
  writer winning

Remember these when specifically thinking about Rust documentation made
me realize that we could get everything into docs.rs.

When doing this
- Tutorial code got brought in as was one of the aims
- We needed to split the lib documentation and the README to have all of
  the linking work.  This allowed us to specialize them according to
  their rule (user vs contributor)
- We needed to avoid users getting caught up in making a decision
  between Derive and Builder APIs so we put the focus on the derive API
  with links to the FAQ to help users decide when to use one or the
  other.
- Improved cross-referencing between different parts of the
  documentation
- Limited inline comments were added to example code
  - Introductory example code intentionally does not have teaching
    comments in it as its meant to give a flavor or sense of things and
    not meant to teach on its own.

This is a first attempt.  There will be a lot of room for further
improvement.  Current know downsides:
- Content source is more split up for the tutorials

This hopefully addresses #3189
2022-07-19 13:30:38 -05:00
Ed Page
a8a7a61f56 chore: Release 2022-07-14 09:38:54 -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
Ed Page
2df0732df4 chore: Release 2022-07-13 09:08:35 -05:00
Emerson Ford
e39156e0b9 feat: Add method to get non-visible arg aliases 2022-07-12 11:23:22 -07:00
Ed Page
9b6321a1f0 chore: Release 2022-07-11 21:48:07 -05:00
Emerson Ford
8e1411b3b2 fix: Loosen lifetime constraint on mut_subcommand 2022-07-11 19:12:36 -07:00
Ed Page
7009ae63c8 doc: Explain why examples are missing
Fixes #3865
2022-06-30 08:29:16 -05:00
Ed Page
6614ffa6c8 chore: Release 2022-06-30 08:25:54 -05: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
b4a1362486 chore: Release 2022-06-28 08:04:18 -05: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
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
Ed Page
f9e51952b8 fix(docs): Update deprecations to latest target
Before, I was mixed on doing this as ideally people would upgrade
through the minor releases, going through the release notes.  This also
saves us havin to audit deprecations to make sure they are all pointing
to the latest.

First, this isn't practical for users.  Its annoying to pin your version (at least
its easier now that we pin `clap_derive` for users) and a lot of work to
go through them one step at a time.

On top of that, we've changed our deprecation policy to put the timing
of responding to deprecations into the user's hands with, with us
putting them behind the `deprecated` feature flag.  This means someone
might respond to deprecations every once in a while or might not do it
until right before the 4.0 release.  Our deprecation messages should be
updated to respond to that.

This supersedes #3616
2022-06-22 14:31:15 -05:00
Ed Page
3823df9bbe chore: Release 2022-06-21 09:32:04 -05:00
Ed Page
01da890145 fix(parser): Don't panic on --=
This broke when we introduced clap_lex and then did a refactor on top.
We put in guards to say that escapes shouldn't happen but missed `--=`
which isn't quite an escape.

Not fully set on what error should be returned in this case (we are
returning roughly what we used to) but at least
we aren't panicing.

Fixes #3858
2022-06-21 08:53:04 -05:00
David Tolnay
690530a191
Fix typo in ErrorKind::ValueValidation message 2022-06-17 13:07:09 -07:00
Ed Page
f131d46b99 fix(parser): Add value_source as a replacement for occurrences_of
This was an oversight when listing out the options as identified when
looking at oxidecomputer/humility#161.
2022-06-16 13:29:31 -05:00
Ed Page
a7698e9a1d chore: Release 2022-06-15 11:50:16 -05:00
Ed Page
40daa70b89 docs: Provide a hybrid-flag example
Between
- `ArgAction::SetTrue` storing actual values
- `ArgAction::Set` making it easier for derive users to override bool
  behavior
- `Arg::default_missing_value` allowing hybrid-flags
- This commit documenting hybrid-flags even further

There shouldn't be anything left for #1649

Fixes #1649
2022-06-15 11:09:53 -05:00
Ed Page
c9988db97f docs(builder): Clean up default_missing_value's docs 2022-06-15 10:59:34 -05:00
Ed Page
eba753f162 fix(help): Further debug clean up 2022-06-15 10:03:52 -05:00
Ed Page
c443aa0b5d refactor(help): Collapse useless function 2022-06-15 09:31:19 -05:00
Ed Page
17d975743a fix(help): Improve debug output 2022-06-15 09:25:18 -05:00
Ed Page
20358ff295 chore: Release 2022-06-14 15:01:42 -05:00
Ed Page
63a17a40ad chore: Release 2022-06-14 11:19:59 -05: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
cb42df61e4 refactor: Switch to once_cell
Though this is changing an API item we export, we do not consider this a
breaking change because
- This was an implementation detail of the macros and people shouldn't be using it directly
- The `macro_rules` macro is coupled to `clap` because they are in the
  same crate
- The derive macro is coupled to `clap` because `clap` declares a
  `=x.y.z` dependency on `clap_derive

Fixes #3828
2022-06-14 09:10:50 -05:00
Ed Page
7836beda05 chore: Release 2022-06-14 07:02:40 -05:00
Ed Page
650a29c18b chore: Release 2022-06-13 09:37:47 -05:00
Ed Page
4e56acffce chore: Release 2022-06-13 09:31:29 -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
97f8041229 fix(assert): Add missing track_caller attributes 2022-06-13 07:04:59 -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
9b7813558c feat(parser): Provide updated version if 'is_present'
- This matches the more container-like naming we are aiming for
- This provides an opportunity to warn people about moving away from
  `ArgAction::IncOcccurrences` for flags, like the deprecation for
  `ArgMatches::occurrences_of` to help people migrate in preparation for
  clap 4 (rather than having the behavior change subtly in a way only
  caught by thorough tests)

In addition, I feel `contains_id` has less ambiguous meaning than
`is_present`.
2022-06-10 10:16:44 -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
54125aca55 docs(parser): Clarify we want arg ids
This was missed in #3453
2022-06-09 17:00:07 -05:00
Ed Page
f87fd0325c fix: Open the door for adding value_parser! specializations
I wanted to make the contract more clear that we might add more specific
value parsers in the future.
2022-06-10 10:52:38 -05:00
Ed Page
af0751c757 fix: Further discourage direct use of ValueParserVia* 2022-06-10 10:30:48 -05:00
Ed Page
8b37be4b01 fix: Further discourage direct use of AutoValueParser 2022-06-10 10:29:06 -05:00
Ed Page
e70b3ff47b fix(parser): Always include pending arguments in errors
Found via cargo's UI tests
2022-06-09 13:41:24 -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
Ed Page
acfb130b0d fix(parser): Prevent rollover of count 2022-06-09 11:05:06 -05:00
Ed Page
01b5e1ee5b perf(builder): Avoid Arc for value parsers
There isn't a strong need for the single-instance at the cost of the
extra book keeping.
2022-06-08 20:57:00 -05:00
Ed Page
d73ff562d1 fix(builder): Move trait requirements closer to the user
My hope is this will provide clearer error messages for the user.
2022-06-08 20:41:51 -05:00
Ed Page
4dc0136b2c fix(parser): Hide AnyValue
With `AnyValueParser` now private, we can also make `AnyValue` private.
Most users should not need to call `ValueParser::parse_ref` and doing
this gives us more implementation freedom for the future.
2022-06-08 20:22:39 -05:00
Ed Page
ebf21a3280 fix(assert): Don't assert in more cases 2022-06-08 17:39:14 -05:00
Ed Page
c61a105e62 fix(builder): Fix regression with auto-help / auto-version 2022-06-08 17:17:50 -05:00
Ed Page
035bc804d1 fix(builder): Dump action in debug output 2022-06-08 16:39:27 -05:00
Ed Page
3052fece16 fix(builder): Make it easier to debug globals 2022-06-08 16:35:56 -05:00
SabrinaJewson
6e49bf7419
refactor: Make AnyValueParser private 2022-06-08 20:36:55 +01:00
Ed Page
aba2a9e84d refactor(builder): Reduce visibility 2022-06-08 14:18:23 -05:00
Ed Page
10bb9abb1a fix(assert): Reference help_expected 2022-06-08 12:06:15 -05:00
Ed Page
28781d6773 fix(help): Deprecate NoAutoVersion/NoAutoHelp
I'm a bit disappointed we don't have a way to control the action for the
help subcommand.  Instead, people will need to provide their own and
disable ours.  Long term, I want to design actions for subcommands but I
don't think its worth keeping `NoAutoHelp` around for it.
2022-06-08 12:02:13 -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
14a62e11fd fix(parser): Deprecate multiple_occurrences
Fixes #3772
2022-06-08 09:54:23 -05:00
Ed Page
b78a0e6ccd style: Make clippy happy 2022-06-08 09:34:20 -05:00
Ed Page
1abc945545 fix(parser): Process overrides with new Actions 2022-06-08 08:59:43 -05:00
Ed Page
7980c5ceb8 fix(parser): Force multiple occurrences with new Actions
This is needed for deprecate `multiple_occurrences`
2022-06-07 14:34:54 -05:00
Ed Page
d88ca13730 docs: Reflect the dropping of occurrences_of 2022-06-07 14:09:08 -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
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
0ba63664fe feat(builder): Offer u64 ranges 2022-06-06 14:02:01 -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
4a694f3592 refactor(parser): Be explicit in checking present values 2022-06-06 12:21:47 -05:00
Ed Page
4489f09f10 feat(parser): Allow querying whether actions take values 2022-06-06 11:20:08 -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
ac64391910 refactor(parser): Remove dead code 2022-06-06 10:15:28 -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
f3bc3d5eb7 fix(error): Don't include default-but-required arguments in usage 2022-06-04 12:58:53 -05:00
Ed Page
5f56e93c0f refactor(parser): Clarify we are working with ids, not names 2022-06-04 12:58:53 -05:00
Ed Page
ccd6663de9 fix(help): Output some bool possible values
Originally I hid all, assuming the flag-only use case but we had to
prevent that from showing up anyways.  For the takes_value case, we
should be showing something since we know what it accepts.  I decided to
only show the most basic values and hide the rest so as to not overwhelm
the user with redundant options and hope the user recognizes they are
redundant.
2022-06-04 12:58:53 -05:00
Ed Page
a3092bafce fix(help): Don't report flag defaults
Now that flags can have meaningful defaults and with defaults being
implicitly set for certain actions, they appear in help but don't quite
make sense.
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
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
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
50f4018dcf fix(parser): Don't treat missing values as missing args 2022-06-02 13:45:18 -05:00
Ed Page
cc2714beab fix(parser): Don't allow error equality
This could cause surprising results for users as we add fields
2022-06-02 13:36:05 -05:00
Ed Page
ab08a3069a docs(builder): Note the type for 'Count' 2022-06-01 16:23:19 -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
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
67f47c5618 feat(parser): SetTrue/SetFalse/Count Actions
This is the minimum set of actions for the derive to move off of
`parse`.  These are inspired by Python's native actions.

These new actions have a "unified" behavior with defaults/envs.  This
mostly means that occurrences aren't tracked.  Occurrences were used as
a substitute for `ValueSource` or for counting values.  Both cases
shouldn't be needed anymore but we can re-evaluate this later if needed.
2022-05-31 21:21:48 -05:00
Ed Page
36680593be refactor(parser): Clarify intent of push_arg_values 2022-05-31 20:46:22 -05:00
Ed Page
7163f8d3e8 refactor(parser): Clarify intent of split_arg_values 2022-05-31 20:46:22 -05:00
Ed Page
e53dd937be feat(builder): Infer takes_vaue from action 2022-05-31 20:46:22 -05:00
Ed Page
91480de6d2 feat(builder): Expose ArgAction 2022-05-31 20:46:22 -05:00
Ed Page
b1b5820cb4 refactor(asserts): Ensure we always check positionals take values 2022-05-31 20:46:22 -05:00
Ed Page
2b95985161 refactor(parser): Ensure action and are are in-sync 2022-05-31 20:45:56 -05:00
Ed Page
7264bf28c7 refactor(parser): Clarify Action::Flag's behavior 2022-05-31 15:11:24 -05:00
Ed Page
eeca653697 refactor(parser): Loosen Action trait requirements 2022-05-31 15:10:07 -05:00
Ed Page
fb99d2c625 refactor(parser): Allow adding more actions in the future 2022-05-31 15:09:30 -05:00
Ed Page
8af7294a26 style: Make clippy happy 2022-05-31 14:50:56 -05:00
Ed Page
12d145c60d style: Fix debug typoe 2022-05-31 14:44:36 -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
c052a976b8 fix(parser): Qualify the type of action
My hope is to add group actions as well, so we need to qualify what kind
of action this is.
2022-05-31 14:22:24 -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
bf7259d644 refactor(parser): Switch positionals to actions 2022-05-31 10:35:54 -05:00
Ed Page
6f5aaab443 refactor(parser): Allow more match-state 2022-05-27 20:10:53 -05:00
Ed Page
0b5de2198e refactor(parser): Don't track the actual identifier
When creating `PendingValues`, I can't have the lifetime.  I could make
it a `Cow` but decided to hold off instead since we don't need this
right now.  Maybe by the time we do need it, we'll have another way of
doing this.
2022-05-27 19:50:47 -05:00
Ed Page
2d8a15453e refactor(parser): Be more explicit that default missing values is not escaped 2022-05-27 19:40:49 -05:00
Ed Page
dc8a7d420e refactor(parser): Switch defaults/envs to actions
There is a default_missing_vals case which is slightly different because
its not actually a default but closing out the remaining argument that
was started in last iteration.
2022-05-27 19:34:19 -05:00
Ed Page
a98075e9cd refactor(parser); Switch default_missing_vals to actions 2022-05-27 19:07:28 -05:00
Ed Page
f0b2924f36 refactor(parser): Match default_missing_vals to rest 2022-05-27 19:06:23 -05:00
Ed Page
e1c5cba5f9 refactor(parser): Extract an occurrence into a reaction 2022-05-27 16:50:28 -05:00
Ed Page
b862fe227a refactor(parser): Generalize the performing of actions 2022-05-27 16:30:38 -05:00
Ed Page
7b6bb32985 refactor(parser): Separate delimiting from storing 2022-05-27 16:27:35 -05:00
Ed Page
e4271d09d9 refactor(parser): Normalize Arg variable names 2022-05-27 15:51:35 -05:00
Ed Page
e41a65d540 style: Fix typos 2022-05-27 13:56:38 -05:00
Ed Page
8f16f2ea41 refactor(parser): Clarify intent for defaults/envs
Especially important is not inferring intent from occurrences as
hopefully that will change with the introduction of actions.
2022-05-27 13:55:54 -05:00
Ed Page
2a409be7a5 refactor(parser): Clarify all ignored parse results 2022-05-27 13:15:34 -05:00
Ed Page
ac8320ddb2 refactor(parser): Make it more clear when we ignore parse results 2022-05-27 12:57:13 -05:00
Ed Page
9f4686714a fix(parser): Always end on required delimited arg
Before, if we were in trailing values that aren't delimite, we wouldn't
respect this flag and end processing of the value, now we do.

This also has a slight perf benefit of us only splitting the value if
the delimiter is present.  We checked for the delimiter anyways, so
doing it first removes a slight bit of work.

I also feel this helps clarify the intended behavior and ooches us
towards a unified code path for actions.
2022-05-27 10:31:10 -05:00
Ed Page
e268dbfbe9 refactor(parser): Clarify value consumption name 2022-05-27 09:23:21 -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
28cb71cddd fix(parser): Pass the intended flag to the action
Inferred flags can make it hard for a future action to trigger behavior
off of the selected alias, like we might want to do for negations, so we
are now translating to the intended arg.

This will also help for debugging.
2022-05-26 16:29:18 -05:00
Ed Page
868320097e refactor(parser): Consolidate help/version handling
This is a step towards user-visible actions
2022-05-26 15:55:48 -05:00
Ed Page
e8e5890f08 refactor(parser): Remove dead code 2022-05-26 09:44:55 -05:00
Ed Page
ae97550638 fix(validator): Deprecate validator_regex
Fixes #3743
2022-05-25 14:32:00 -05:00
Ed Page
fcdd31781b feat(parser): Allow people to plug into 'value_parser' macro
For most users, this won't be worth doing, they can just specify the
parser if needed.  Where this has value is crates that integrate custom
types into clap, like creating click-like file integration.  See
https://click.palletsprojects.com/en/8.0.x/arguments/#file-arguments
2022-05-25 14:12:27 -05:00
Ed Page
814d30b1de fix(parser): Deprecate is_valid_arg 2022-05-25 13:00:51 -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
5b6d68f247 fix(parser): Show cause of panic in backtrace 2022-05-25 12:57:11 -05:00
Ed Page
9b5b49ceec fix(parser): Error, don't panicon on get_many type mismatch 2022-05-25 12:57:11 -05:00
Ed Page
a1df333ccd fix(parser): Improve panic messages for get_one, etc 2022-05-25 12:10:30 -05:00
Ed Page
bac68e5d30 docs(parser): Fix links 2022-05-25 11:00:46 -05:00
Ed Page
18793d9db7 docs(parser): Fix typos 2022-05-25 10:56:48 -05:00
Ed Page
21be77c854 docs(parser): Group args / subcommand funcs separately 2022-05-25 10:52:02 -05:00
Ed Page
eda0ca54c1 fix(parser): Simplify the common getter API
Clap has focused on reporting development errors through assertions
rather than mixing user errors with development errors.  Sometimes,
developers need to handle things more flexibly so included in #3732 was
the reporting of value accessor failures as internal errors with a
distinct type.  I've been going back and forth on whether the extra
error pessimises the usability in the common case vs dealing with the
proliferation of different function combinations.  In working on
deprecating the `value_of` functions, I decided that it was going to be
worth duplicating so long as we can keep the documentation focused.
2022-05-25 10:50:42 -05:00
Ed Page
53948db66f style: Make clippy happy 2022-05-25 10:25:57 -05:00
Ed Page
78b6f1ee64 fix(parser): Default construct ArgMatches::remove_many's Iterator 2022-05-25 10:19:05 -05:00
Ed Page
2891a73b2e fix(parser): Default construct ArgMatches::get_many's Iterator 2022-05-25 10:19:05 -05:00
Ed Page
a4e8cc96f9 fix(parser): Default construct ArgMatches::get_raw's Iterator 2022-05-25 10:19:05 -05:00
Ed Page
ed45de2f03 fix(parser): Clean up remove types
The remove functions no longer return `Arc` but the core type, at the
cost of requiring `Clone`.  I originally held off on this
in #3732 in the hope of gracefully transition the derive and requiring
`Clone` would have been a breaking change but when it came to #3734, I didn't
find a way to make it work without a breaking change, so I made it
opt-in.  This means I can force the `Clone` requirement now.

I added the requirement for `Clone` everywhere else in the hopes that in
the future, we can drop the `Arc` without a breaking change.
2022-05-24 16:25:07 -05:00
Ed Page
9a913c40e1 fix(help): Show possible values long help 2022-05-24 14:53:08 -05:00
Ed Page
c6a3871544 fix(error): Include PossibleValuesParser values in error 2022-05-24 14:53:08 -05:00
Ed Page
30f2879824 fix: Include value_parser in debug output 2022-05-24 14:53:08 -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
852a1b15d4 fix(help): Show value_parser's PossibleValues 2022-05-20 19:59:36 -05:00
Ed Page
5b4ea8e56e fix(parser): Print proper upper range bound 2022-05-20 19:48:06 -05:00
Ed Page
1446be8a89 feat(derive): Allow destructively constructing from ArgMatches 2022-05-18 09:10:55 -05:00
Ed Page
5171fce186 fix(parser): Use optimized bool value parser 2022-05-20 12:50:52 -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
acdf26ac38 style: Make clippy happy 2022-05-17 17:13:08 -05:00
Ed Page
c9e3b81e3c doc(parser): Specify what unwraps are for 2022-05-17 16:58:38 -05:00
Ed Page
91fe9eedc9 feat(parser): Transfer ownership of sub-matches 2022-05-17 16:58:38 -05:00
Ed Page
675ac68f73 fix(parser): Give more flexibility for changes 2022-05-17 16:58:38 -05:00
Ed Page
0033bf60c1 style: Address clippy complaints 2022-05-17 14:11:04 -05:00
Ed Page
63aa236141 feat(parser): Convenient range value parsers
There are several approaches with this
- `value_parser(N..M)`: creates an i64 range
- `value_parser(value_parser!(u16).range(10..))`: creates an u16 range
  that starts at 10
- `RangeI64ValueParser`: create whatever range you want

I was hoping to generalize `RangeI64ValueParser` for any source type,
not just i64, but ran into issues and decided to punt.  I chose `i64` as
the source type as it seemed the most general and didn't run into
portability issues like `isize`.

This is a step towards #3199.  All that is left is for the derive to use
this.
2022-05-17 14:00:52 -05:00
Ed Page
6b0306df9e feat(parsr): Expose all built-in TypedValueParsers
This makes life easier for people, whether they want a geneirc
`NonEmpty<impl TypedValueParser>` or a `PathBufExists(PathBuf)`.
2022-05-16 17:16:42 -05:00
Ed Page
2ffa38f9f5 feat(parser): Implicitly turn possible values into a value parser 2022-05-16 17:07:35 -05:00
Ed Page
f86d881e3a docs(parser): Polish ValueParser docs 2022-05-16 16:54:05 -05:00
Ed Page
41f13bd0ce feat(complete): Path value parsers imply Path completion hints 2022-05-16 15:15:55 -05:00
Ed Page
d2ca18130e feat(parser): Allow removing values from ArgMatches
This allows reducing the use of `Clone`, especially in `clap_derive`.
2022-05-16 15:08:47 -05:00
Ed Page
792fb54990 fix(parser): Be consistently strict with ArgMatches types
This gives us more implementation freedom for the future.
2022-05-16 15:08:47 -05:00
Ed Page
c7bd8c891d perf(parser): Don't allocate on every call 2022-05-16 15:08:47 -05:00
Ed Page
36236957e4 fix(parser): Allow invalid id lookups without panics
Fixes #3621
2022-05-16 15:08:47 -05:00
Ed Page
c331be98a5 fix(parser): Separate dev errros from user errors 2022-05-16 15:08:47 -05:00
Ed Page
66570ee9d0 refactor(parser): Set source at start of occurrence 2022-05-16 15:08:47 -05:00
Ed Page
7cb2a096d0 refactor(parser): Force explicit occurrence start 2022-05-16 15:08:47 -05:00
Ed Page
0d6be4e1a8 refactor(parser): Consistently start occurrences 2022-05-16 15:08:47 -05:00
Ed Page
5532bfc838 refactor(parser): Clarify env code 2022-05-16 15:08:47 -05:00
Ed Page
4845296949 refactor(parser): Clarify default value code 2022-05-16 15:08:47 -05:00
Ed Page
8a58884459 refactor(parser): Initialize MatchedArg from its source 2022-05-16 15:08:47 -05:00
Ed Page
e6b1468477 fix(parser): Set source/occurrences for external subcommands 2022-05-16 15:08:47 -05:00
Ed Page
d538012a74 refactor(parser): separate concerns over external subcommands 2022-05-16 15:08:47 -05:00
Ed Page
0e04367826 fix(parser): Consistently log parser 2022-05-16 15:08:47 -05:00
Ed Page
c74d3fb045 refactor(parser): Reduce visibility 2022-05-16 15:08:47 -05:00
Ed Page
144cd4c3b7 refactor(parser): Group default/env 2022-05-16 15:08:47 -05:00
Ed Page
8c3f540638 refactor(parser): Clarify name for starting occurrences 2022-05-16 15:08:47 -05:00
Ed Page
f296c5ca78 refactor(parser): Fix naming of ty 2022-05-16 15:08:47 -05:00
Ed Page
bc6da813bd fix(parser): Unify handling of AnyValue's type id 2022-05-16 15:08:47 -05:00
Ed Page
9920d5baf5 fix(parser): Improve AnyValue debug output 2022-05-16 15:08:47 -05:00
Ed Page
8b582c3007 refactor(parser): Make AnyValue opaque
This gives a little more implementation flexibility
2022-05-16 15:08:47 -05:00
Ed Page
f16a6fb5a6 refactor(parser): Move AnyValue definition closer to use 2022-05-16 15:08:47 -05:00
Ed Page
bdf9d841ef doc(parser): Expand examples for ValueParser
This identified a problem with the blanket implementations for
`TypedValueParser`: it only worked on function pointer types and not unnamed
function tupes.  The user has to explicitly decay the function type to a
function pointer to opt-in, so I changed the blanket impl.  The loss of
the `OsStr` impl shouldn't be too bad.
2022-05-16 15:08:47 -05:00
Ed Page
6f2c4aff90 refactor(parser): Clean up ValueParser 2022-05-16 15:08:47 -05:00
Ed Page
f3d8ef248f feat(complete): Complete value_parser possible values 2022-05-16 15:08:47 -05:00
Ed Page
0088b1643c feat(parser): Track ValueParser's possible values
This will let us replace `Arg::possible_values` completely by letting
completions check these.
2022-05-16 15:08:47 -05:00
Ed Page
2e57f1fca7 fix(parser): Disallow empty paths 2022-05-16 15:08:47 -05:00
Ed Page
ec186487b6 refactor(parser): Have ValueParser delegate built-ins 2022-05-16 15:08:47 -05:00
Ed Page
f9be3215c1 refactor(parser): Minor clean up 2022-05-16 15:08:47 -05:00
Ed Page
352025f8cb refactor(parser): Tweak specialization precedence
In theory, directly implemented types should have higher precedence than
inferring from another trait.
2022-05-16 15:08:47 -05:00
Ed Page
50e7308c22 refactor(parser): Reduce chance of bugs in specialization 2022-05-16 15:08:47 -05:00
Ed Page
a3965918bc doc(parser): Explain built-in motivation 2022-05-16 15:08:47 -05:00
Ed Page
d52be32e8e fix(parser): Don't bake-in ArgEnum 2022-05-16 15:08:47 -05:00
Ed Page
a798858ced feat(parser): Verify possible values 2022-05-16 15:08:47 -05:00
Ed Page
9d07b3c028 feat(parser): non-empty string ValueParser 2022-05-16 15:08:47 -05:00
Ed Page
ecc5b2f3e9 feat(parser): Support ArgEnum with ValueParser 2022-05-16 15:08:47 -05:00