Commit graph

2872 commits

Author SHA1 Message Date
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
Ed Page
2902f190e4 refactor(error): More flexible callers 2022-05-16 15:08:47 -05:00
Ed Page
56aaf0baf2 feat(parser): Expose env-like bool parsers
Still unsure what should be the default but this at least makes it
easier for people to choose.
2022-05-16 15:08:47 -05:00
Ed Page
73fc240c57 refactor(env): Generalize bool policy 2022-05-16 15:08:47 -05:00
Ed Page
200f6626db feat(parser): Add type information to arg values
To set the type, we offer
- `ValueParser::<type>` short cuts for natively supported types
- `TypedValueParser` for fn pointers and custom implementations
- `value_parser!(T)` for specialized lookup of an implementation
  (inspired by #2298)

The main motivation for `value_parser!` is to help with `clap_derive`s
implementation but it can also be convinient for end-users.

When reading, this replaces nearly all of our current `ArgMatches` getters with:
- `get_one`: like `value_of_t`
- `get_many`: like `values_of_t`

It also adds a `get_raw` that allows accessing the `OsStr`s without
panicing.

The naming is to invoke the idea of a more general container which I
want to move this to.

The return type is a bit complicated so that
- Users choose whether to panic on invalid types so they can do their
  own querying, like `get_raw`
- Users can choose how to handle not present easily (#2505)

We had to defer setting the `value_parser` on external subcommands,
for consistency sake, because `Command` requires `PartialEq` and
`ValueParser` does not impl that trait.  It'll have to wait until a
breaking change.

Fixes #2505
2022-05-16 15:08:33 -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
cf0282bdae refactor: Remove dead code 2022-05-12 10:35:52 -05:00
Andreas Backx
a678baa4f4
feat(builder): Updated min_value and required docs 2022-05-14 21:06:52 +01:00
Ed Page
399c138825 fix: Soft-deprecate several items within the root 2022-05-12 06:18:08 -05:00
Ed Page
4fea1515b6 feat: Expose builder/parser modules
The top-level API for clap is getting a bit bloated.  By exposing these
modules, we'll be able to continue to add new, less commonly used types
while keeping the main API focused.
2022-05-12 06:17:08 -05:00
Ed Page
524e36cf1a chore: Release 2022-05-10 15:29:16 -05:00
Ed Page
52f6939044 fix(macros): Add needed call for arg_enum
Fixes #3717
2022-05-10 14:43:04 -05:00
Ed Page
7c1f9123a4 fix(assert): Make sure group members exist before using them
In #3711, we had a confusing assert about no non-default members of a
required group when there were no defaults involved.  This is because
there were no valid args in the group but that check happens after.
2022-05-09 15:53:18 -05:00
Ed Page
eb155786bb fix(parser): Assert on unknown args when using external subcommands (unstable) 2022-05-06 15:49:33 -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
Ed Page
6ceb865c95 fix(assert): Detect conflicting arguments (unstable)
Fixes #3660
2022-05-06 14:29:35 -05:00
Ed Page
3d7ee2e5cd fix(assert): Verify required_unless_present_all exist 2022-05-06 14:11:37 -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
Ed Page
55e791e80e chore: Release 2022-05-06 11:57:48 -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
17b930c203 chore: Release 2022-05-05 21:04:09 -05:00
Ed Page
05aecf8248 refactor(help): Remove more redundant required checks
Made redundant in #3689 but missed updating these.
2022-05-05 20:33:39 -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
f7c2deaa47 fix(help): Don't show hidden arguments for conflicts
This makes it consistent with other errors where we show arguments to
the user.
2022-05-05 12:16:56 -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
e4c096ea99 fix(help): Use display name instead of bin name (unstable-v4)
This will mean we won't have an awkard `.exe` in the middle on Windows

This means users can have a display name for their application rather
than it being dependent on the binary name it was run as

This means users can manually set it to use spaces instead of dashes for
separating things out.

Fixes #992
Fixes #1474
Fixes #1431
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
8bea44d745 docs(help): Document name help_template variable 2022-05-04 14:43:58 -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
88472224dc perf(parser): Short-circuit exclusive validation 2022-05-04 12:13:51 -05:00
Ed Page
aa6026f43c docs(multicall): Expand documentation in prep for stablization 2022-05-03 16:26:01 -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
0240ec5493 chore: Release 2022-05-02 13:02:10 -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
5e02ac1c19 chore: Release 2022-04-30 20:21:33 -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
c6849e2ebd fix(debug): Moe detail 2022-04-30 19:07:42 -05:00
Ed Page
b01256be36 chore: Release 2022-04-30 06:36:33 -05:00
Ed Page
8df20478a4 style: Make clippy happy 2022-04-29 20:26:59 -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
515a37dba1 fix(debug): Improve debug output of bin building 2022-04-29 16:18:30 -05:00
Ed Page
bcde91b101 fix(debug): Update Command's debug statements 2022-04-29 16:07:47 -05:00
Ed Page
ba0301d9b4 refactor(builder): Group related build functions 2022-04-29 09:36:28 -05:00
Ed Page
7113e46388 fix(builder): Deprecate public Command::_build_bin_names 2022-04-29 09:21:42 -05:00
Ed Page
397e8443f9 refactor(builder): Consistently use internal function 2022-04-29 09:16:20 -05:00
Ed Page
9f9e410c6d feat(complete): Minimal rust-completion
Inspired by argcomplete, this provides Rust-implemented completions
- Only bash for now
- No subcommand support
- No flag value support
- No special settings support
- No handling of positions within positionals
- No prioritizing of required or removing of conflicts (including
  self-conflicts)
2022-04-27 15:49:58 -05:00
Ed Page
d4ddc5f6d6 clap(debug): More conflict details 2022-04-27 12:38:12 -05:00
Ed Page
f083ef92c5 fix(lex)!: Don't do prefix matching by default
Finding this a pain in `clap_complete`; not offering the benefits I
expected.
2022-04-27 12:38:12 -05:00
Ed Page
5ae9c75324 fix(clap): Allow disabling color with debug 2022-04-22 12:32:58 -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
4e20af3498 refactor(parser): Reduce visibility of parser fields 2022-04-22 07:03:07 -05:00
Ed Page
d805c6031d chore: Release 2022-04-22 06:52:05 -05:00
Arlo Siemsen
854017b478 fix: Mixup between stderr and stdout introduced in v3.1.11 2022-04-22 02:09:22 -05:00
Ed Page
a46ee83224 chore: Release 2022-04-21 20:08:49 -05:00
Ed Page
9d523012fe refactor(validator): Decouple parser 2022-04-21 16:31:04 -05:00
Ed Page
6229e78bc6 refactor(parser): Parser is solely responsible for populating ArgMatches 2022-04-21 16:24:10 -05:00
Ed Page
02ffd59830 refactor(help): Move help writing down a layer 2022-04-21 16:14:11 -05:00
Ed Page
ebeade91bf refactor(help): Consolidate help errors 2022-04-21 16:12:01 -05:00
Ed Page
6a9a5d05b0 refactor(help): Make bool's meaning clearer 2022-04-21 16:01:47 -05:00
Ed Page
639f9e8849 refactor(parser): Pull out long-help determination
This isn't a parser policy but command-level policy.
2022-04-21 15:49:02 -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
de89c050c9 fix(validate): Consistent conflict behavior
We had two different implementations of conflicts
- Validating conflicts
- Allowing conflicts to override `required`
  - Missing members of a group conflicting with each other
  - Missing symmetric conflicts (A conflicts with B so B conflicts with
    A)

This consolidates their implementations which should fix overriding of
`required`.
2022-04-21 15:03:56 -05:00
Ed Page
0194568b03 chore: Release 2022-04-19 10:31:52 -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
Ed Page
7598c000f9 chore: Release 2022-04-15 14:39:14 -05:00
Ed Page
7849c35a3e
Merge pull request #3635 from epage/port
feat: Expose clap_lex
2022-04-15 14:00:28 -05:00
Ed Page
15d8b3b0cd style: Make clippy happy 2022-04-15 13:49:02 -05:00
Ed Page
e46cf659d6 fix(lex): Provide all dat with ParsedArg::to_value 2022-04-15 12:40:05 -05:00
Ed Page
96dc6daa9e feat(lex): Pull out clap_lex 2022-04-15 10:55:37 -05:00
Ed Page
6291289c0f fix(lex): Make long args more convinient 2022-04-15 10:55:34 -05:00
Ed Page
1247a955cf docs(lex): Specify how it all works 2022-04-15 10:55:28 -05:00
Ed Page
6148d681f4 refactor(lex): Clarify side effects 2022-04-15 10:55:25 -05:00
Ed Page
fd16ee9474 refactor(lex): Port to expanded lexer 2022-04-15 10:55:19 -05:00
Ed Page
6e05b8075b refactor(lex): Expand lexer design
In considering the design for this, we want:
- Ability to modify the argment list while maintaining the `Cursor` for
  replacements
- Allow picking up subcommand parsing in the middle of short flags
- Ability to peek at the next item to determine if we want to treat it
  as a flag or as a value
- Ability to detect started short and long arguments for completions

Longer term, we also want to consider:
- Allowing users to customize the lexer to support different syntaxes
2022-04-15 10:55:12 -05:00
Ed Page
c58928b6bd refactor(lex): Track replacements as str
The lexer will soon return `RawOsStr` and it'll cost to turn that into
an `OsStr`.  However, it caches a `str`, so let's just use that.
2022-04-15 10:55:08 -05:00
Ed Page
f66d8abebd refactor(lex): Experiment with an alt 'previous'
Since we'll need `skip`, it made me wonder how to name `skip` and
`previous` to fit together, so I decided to play with `seek`.  Its
probably over kill but wondering if its better.
2022-04-15 10:55:05 -05:00
Ed Page
3ebf61e28d refactor(lex): Narrow focus for lexer
Before, we had a generic `next` that provided the next item and peeked
at all remaining items.  This was to work around the borrow checker for
modifying the position while accessing args.

We've now split `Input` into `RawArgs` and `ArgsCursor` so we don't have
overlapping borrows.  This made it so we can split `next` into `next`,
`peek`, and `remaining`.
2022-04-15 10:55:00 -05:00
Ed Page
0000d506ed refactor(lex): Remove unused bound 2022-04-15 10:54:50 -05:00
Ed Page
65120784f5 refactor(lex): Split out input cursor 2022-04-15 10:54:43 -05:00
Chloe-Woahie
87c87565af docs: Fixed documentation typos 2022-04-10 12:43:09 -04:00
Ed Page
a3b628998d docs: Don't encourage index
Its extra maintenance and more likely to cause annoyances.

Fixes #3608
2022-04-04 08:52:20 -05:00
Ed Page
08f74046dc chore: Release 2022-04-01 09:15:32 -05:00
Kevin Moonen
17fed36da3 fix: Bring forward Debug impls from v2 2022-03-31 22:45:37 -05:00
Ed Page
c75d2642ef chore: Release 2022-03-31 12:22:40 -05:00
Samuel Tardieu
ef3c2c73d5 docs: arg! macro uses double quotes for help string 2022-03-25 11:00:47 +01:00
Grachev Mikhail
02d4d6b137
chore: fix typo 2022-03-14 14:45:42 +03:00
Thayne McCombs
2b86726879 docs: Document grouped_values_of
Relates to #2924
2022-03-10 00:53:46 -07:00
Ed Page
e702f42e5e chore: Release 2022-03-07 10:40:48 -06:00
plaflamme
b6df23dc14
fix: Multiple defaults combined with ArgEnum 2022-03-06 23:10:16 -05:00
Ed Page
c6d456f608 fix(builder): Tell users cargo feature is needed
This will help in cases like #3530
2022-03-03 12:43:10 -06:00
Ed Page
e937955efb chore: Release 2022-03-02 09:49:11 -06:00
Ed Page
1e286f3dc2 chore: Release 2022-03-02 09:20:00 -06: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
63fa59a251 chore: Release 2022-02-28 10:03:45 -06:00
Ed Page
3f2a37088b fix(assert): Validate delimited defaults
Fixes #3514
2022-02-28 09:21:44 -06:00
Ed Page
20dc6673bc chore: Release 2022-02-23 09:39:40 -06:00
Ed Page
655c3f0b9f chore: Release 2022-02-21 07:50:28 -06:00
Ed Page
006a161e39
Merge pull request #3492 from kornelski/trac
More track_caller
2022-02-21 07:48:19 -06:00
Ed Page
fa24b9f173 docs: Tell people to use latest API
Fixes #3478
2022-02-16 16:27:44 -06:00
Kornel
2437051eff More track_caller 2022-02-16 18:40:20 +00:00
Ed Page
e6729f96c3 chore: Release 2022-02-16 11:59:45 -06:00
Ed Page
3dd3993682 docs(builder): Add ToC to Command, Arg 2022-02-15 11:40:58 -06:00
Ed Page
94e2727bd0 docs(builder): Clarify command-wide 2022-02-15 11:30:26 -06:00
Ed Page
15c7abb196 docs(parser): Fix ArgMatches::value_source documentation 2022-02-15 11:23:40 -06:00
Ed Page
b171802265 docs: Ensure IntoApp is visible 2022-02-15 11:16:22 -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
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
9a7e6a523d fix: Deprecate App 2022-02-14 15:34:27 -06:00
Ed Page
c4144d7d6c docs: Update App references to Command 2022-02-14 15:33:49 -06:00
Ed Page
524e164c31 fix: Rename App to Command 2022-02-14 15:32:07 -06:00
Ed Page
06b269a85a refactor: Rename Apps file 2022-02-14 15:29:26 -06:00
Ed Page
44d85344a9 refactor: Be consistent in mod visibility 2022-02-14 15:28:38 -06:00
Ed Page
a627778809 refactor: Generalize test file name 2022-02-14 14:42:23 -06:00
Ed Page
3475555de6 fix(help): Use standard alternate syntax for subcommands 2022-02-14 21:18:33 -06:00
Ed Page
9a83ada940 fix(help): Separate subcommand flags 2022-02-14 16:20:33 -06:00
Ed Page
8c5e42e0fb fix(help): Show subcommand flags in same order as usage 2022-02-14 16:20:03 -06:00
Ed Page
77542a1138 refactor: Reduce visibility on App members
The long term goals are
- Easier refactoring
- Identify needs for reflection API

Shorter term, if I want to rename `App` to `Command` and deprecate
`App`, it will mark all member access as deprecated.  This works around
that.

I gave up in exploring abstractions when it came to `MKeyMap` access.
This can be refined in the future.
2022-02-14 14:17:48 -06:00
Ed Page
58000253d7 refactor: Clarify role of usage name 2022-02-14 12:52:37 -06:00
Ed Page
235cbb615e refactor: Centralize build logic 2022-02-14 12:52:37 -06:00
Ed Page
3f32030f7f refactor: Delay collecting required
The main goal is to allow centralizing some building logic currently
split between the parser and `App`.  It depends on this logic.

As a side benefit, this allowed us to decouple some operations from `Parser` in `App`.

The main impact I can see is that we'll calculate the required once for
parsing a subcommand and once for validation.
2022-02-14 12:52:37 -06:00
Ed Page
b994789ee6 refactor: Prepare for deferring graph creation 2022-02-14 12:52:37 -06:00
Ed Page
54c2f0df05 refactor: Open door for multiple writes 2022-02-14 12:52:37 -06:00
Ed Page
6886109fa6 refactor: Make use refactor friendly 2022-02-14 12:52:37 -06:00
Ed Page
6c7126b156 docs: Hide items deprecated in 3.0.0
We left them in the docs for a period of time to help people find docs
for code that was still in use.  Balancing that with the need for clean
docs, it seems like 3.1 is an appropriate time to mark them hidden in
the docs.
2022-02-11 18:42:28 -06:00
Ed Page
97e36451cf docs: Update stale references to AppSettings 2022-02-11 15:58:12 -06: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
c0fd6753ea refactor(validate): Clarify subcmd check intent 2022-02-11 14:55:57 -06:00
Ed Page
8e5ce6c044 refactor(validate): Drop us to one req check 2022-02-11 14:36:42 -06:00
Ed Page
9824f8d0ba perf(validate): Remove unnecesarry walking of args 2022-02-11 14:27:18 -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
de7c81e059 fix(error): Deprecate WaitOnError
Fixes #3439
2022-02-11 09:00:10 -06:00
Ed Page
547665d52a fix(color): Allow overriding previous settings 2022-02-11 09:00:10 -06:00
Ed Page
bdb034b1b5 docs: Clarify app-wide vs command-specific settings 2022-02-11 09:00:10 -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
60a8747603 refactor: Flatten directory heirarchy 2022-02-10 11:17:08 -06:00
Ed Page
fb9e4e7c25 refactor: Centraize all debug asserts 2022-02-10 11:10:34 -06:00
Ed Page
b7842c2e11 refactor: Flatten directory heirarchy 2022-02-10 11:07:57 -06:00
Ed Page
727c453322
Merge pull request #3434 from epage/setting
feat: Add `Arg` getters for all settings
2022-02-10 10:37:59 -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
Malloc Voidstar
bd49665bd5
docs: validator takes &str, not String
Explicit link removed as it doesn't appear to be necessary
2022-02-09 21:03:19 -08:00
Ed Page
81092b5aed fix: Detect deeply recursed global args
Fixes #3428
2022-02-09 16:05:27 -06:00
Ed Page
82dfc7d5ea perf: Reduce parse allocations 2022-02-09 15:24:52 -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
df1d50c367 fix: Easier to debug help flags 2022-02-08 18:51:51 -06:00
Ed Page
12c29526fa fix(parser): Give room for more ValueSources 2022-02-08 15:05:59 -06:00
Ed Page
f42fc89288 fix(parser): Remove an internal-only ValueSource 2022-02-08 15:05:59 -06:00
Ed Page
edda56f072 feat(parser): Expose ValueSource
Fixes #1345
2022-02-08 15:05: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
25b8fe8edb Revert "Revert "Revert "Revert "docs: Clarify corner caseses with default values""""
This reverts commit 26bbe606d3.
2022-02-08 12:27:52 -06:00
Ed Page
e87881f91a fix(validate): Limit relationship checks to non-defaults 2022-02-08 12:17:39 -06:00
Ed Page
f59c82bc1d refactor(validate): Clarify intent of code 2022-02-08 11:52:07 -06:00
Ed Page
279e39a858 fix(validate): Only check requires when target is set by user
Unrolling serves two distinct purposes but we muddied them together
- Is `requires` satisfied for validation
- Report what arguments are currently considered required for usage

This was split out of #3020
2022-02-08 11:24:47 -06:00
Ed Page
2b265ea81a fix(validate): Only check if value is set by user
This was split out of #3020
2022-02-08 08:12:39 -06:00
Ed Page
f830bf93b0 refactor(validate): Generalize contains_explicit 2022-02-08 08:11:46 -06:00
Ed Page
3a517b6583 refactor(validate): Centralize all required logic 2022-02-08 07:34:11 -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
16bf834aa5 refactor: Prepare for overriding derived display order 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
4f50e97f23 docs: Prepare for 3.1 deprecations
Don't want to forget this remaining work
2022-02-07 19:17:09 -06:00
Ed Page
07e4e424ac perf(error): Take arond 5kb off 2022-02-07 14:55:24 -06:00
Ed Page
e3e0a91561 fix(error): Don't overload fields 2022-02-07 14:47:49 -06:00
Ed Page
84416b267c style: Make clippy happy 2022-02-07 13:06:04 -06:00
Ed Page
600d741d65 feat(error: Expose unknown-argument context 2022-02-07 13:03:23 -06:00
Ed Page
6079bae959 perf: Reduce binary size by 11k 2022-02-07 12:35:23 -06:00
Ed Page
3f06e13a85 feat(error: Expose argument-not-found context 2022-02-07 10:58:02 -06:00
Ed Page
a4b044df81 feat(error: Expose unexpected-multiple context 2022-02-07 10:32:42 -06:00
Ed Page
2434f51129 feat(error: Expose wrong-number context 2022-02-04 14:52:31 -06:00
Ed Page
7497dbb6cc feat(error: Expose value-validation context 2022-02-04 14:35:52 -06:00
Ed Page
3d4f31b223 feat(error: Expose too-few context 2022-02-04 14:24:46 -06:00
Ed Page
ee2860e434 feat(error: Expose too-many-values context 2022-02-04 14:10:16 -06:00
Ed Page
2b60c598b7 feat(error: Expose too-many context 2022-02-04 13:53:57 -06:00
Ed Page
03fbb50283 refactor(error): Make room for more values 2022-02-04 13:44:49 -06:00
Ed Page
f7731d1f03 feat(error: Expose invalid-utf8 context 2022-02-04 13:42:36 -06:00
Ed Page
f54bcc85b7 feat(error: Expose missing-subcommand context 2022-02-04 13:18:51 -06:00
Ed Page
9b18f8087c feat(error: Expose missing-required context 2022-02-04 12:45:48 -06:00
Ed Page
71535866b9 feat(error: Expose invalid-subcommand context 2022-02-04 12:23:06 -06:00
Ed Page
5095e5c992 feat(error: Expose unrecognized-subcommand context 2022-02-04 11:15:22 -06:00
Ed Page
1a0d7bac29 feat(error: Expose invalid-value context 2022-02-04 10:24:51 -06:00
Ed Page
04aa6029b8 refactor(error): Generalize kind name 2022-02-04 10:08:51 -06:00
Ed Page
1463f82cf1 feat(error: Expose no equals context 2022-02-04 10:07:14 -06:00
Ed Page
9759f2f1ea refactor(error): Share template across kinds 2022-02-04 10:03:09 -06:00
Ed Page
630e7097fc feat(error: Expose empty value context 2022-02-04 10:01:07 -06:00