Commit graph

2389 commits

Author SHA1 Message Date
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
Ed Page
0c36fc2073 feat(error): Expose argument conflict context 2022-02-04 09:59:06 -06:00
Ed Page
7029e76545 refactor(error): Prepare for deferring formatting 2022-02-04 09:56:22 -06:00
Ed Page
c002951dc8 refactor(error): Centralize app knowledge 2022-02-04 09:51:34 -06:00
Ed Page
ee63f6cd9b refactor(error): Prepare for optional deferred formatting 2022-02-04 09:45:12 -06:00
Ed Page
af41e8d6b2 refactor(error): Separate try_help concerns 2022-02-04 08:49:55 -06:00
Ed Page
8de99407f9 feat(error): Impl Display for ErrorKind 2022-02-04 08:37:23 -06:00
Ed Page
4add5723ec refactor(error): Don't constrain start of errors
This also makes the intent for the start of an error clearer.
2022-02-04 08:21:24 -06:00
Ed Page
70b830a1ad refactor(error): Prepare for adding more app fields 2022-02-03 13:05:10 -06:00
Ed Page
00af9c11f8 refactor(error): Shift focus to modern fields 2022-02-03 12:59:59 -06:00
Ed Page
27469dc740 refactor(error): Centralize new formatting 2022-02-03 12:36:20 -06:00
Ed Page
1b66585dc2 feat(error): New error context API
This is meant to replace `Error::info` as part of #2628.
2022-02-03 12:30:49 -06:00
Ed Page
59b63aea51 refactor(error): Pull out kind mod 2022-02-02 16:13:26 -06:00
Ed Page
2d01331540 refactor(error): Prepare for splitting mod 2022-02-02 16:06:23 -06:00
Ed Page
03832c75b9 refactor: Reduce reliance on soon-to-deprecate kind 2022-02-02 15:47:47 -06:00
Ed Page
3b516a4d62 perf(error): Reduce stack size of Error 2022-02-02 15:46:45 -06:00
Ed Page
a889797c27 fix(error): Allow Result interoperability 2022-02-02 15:43:07 -06:00
Ed Page
b538a43961 refactor(error): Switch to error::ErrorKind 2022-02-02 15:41:24 -06:00
Ed Page
5535f49d13 fix(error): Expose the error module
We'll be expanding whats included and we shouldn't spam the root as
much.
2022-02-02 15:35:20 -06:00
Ed Page
b55edfa740 refactor: Rename errors mod
It seems that `error` is more common (e.g. `nom`)
2022-02-02 15:34:17 -06:00
Ed Page
9d482d00ba feat(error): Show possible values when none are supplied
This is inspired by cargo which allows you to run `cargo test --test`
and it will list the possible tests (obviously we can't support that atm
because that requires a lot of runtime processing).  When we do have a
static list of possible values, we can at least show those.

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

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

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

This was split out of #3020
2022-02-02 13:30:23 -06:00
Ed Page
d376865c18 refactor: Clarify intent behind requires
This is based on the work in #3384
2022-02-01 16:51:55 -06:00
Ed Page
c0b12c7260 refactor: Clarify intent of default_value_if
While this doesn't help in the public API (yet), this at least clarifies
the intent in the implementation.

This is building towards #3020.
2022-02-01 16:38:05 -06:00
Ed Page
dc035de409 chore: Release 2022-02-01 16:11:53 -06:00
Ed Page
50a58e98eb feat(parser): Check if args were present
In clap2, `ArgMatches.args` was public but hidden.  We made it private
in clap3, giving us more implementation flexibility but many people
relied on it, like to short-circuit defaulting, providing their own
`ArgRequiredElseHelp`, etc.

The main problem was how to expose this
- If we think of `ArgMatches` as a container (a DAG), should we have an
  `is_empty` and what all is included in that, like subcommands?
- If we focus on only args, what term how do we refer to this to convey
  the right intent?

In the end, I realized that this aligns most with our existing
`is_present` check and reporting if args are present fits the best
within the existing API.

I looked into also exposing iterating over the args (`present_arg_ids`)
but we have no way to expose the Id.  The Id is currently private and if
we made it public, it can't be used to access any arg because it can't
implement `Key`.

This supersedes #3265
2022-02-01 15:52:21 -06:00
Ed Page
3722270e47 style: Clippy 2022-02-01 13:56:45 -06:00
Ed Page
c638330e85 refactor: Reduce what Parser visibility we can 2022-02-01 13:44:55 -06:00
Ed Page
05f8151d3d fix(usage): Track all required 2022-02-01 13:38:23 -06:00
Ed Page
232c17ebc4 refactor(help): Decouple from parser 2022-02-01 13:23:58 -06:00
Ed Page
3cd9174f48 refactor(usage): Decouple from the parser
This is a step towards removing `pub(crate)` and for moving usage/help
out of the core clap generally.
2022-02-01 12:42:32 -06:00
Ed Page
ac50402778 refactor: Reduce visibility of PossibleValue members 2022-02-01 11:27:45 -06:00
Ed Page
b2c7572643 refactor: Reduce visibility of MatchedArg members 2022-02-01 11:27:45 -06:00
Ed Page
cd6e009c83 refactor: Reduce visibility of ArgMatcher members 2022-02-01 11:27:08 -06:00
Ed Page
4538d618a7 refactor: Migrate off of .kind 2022-02-01 11:27:08 -06:00
Ed Page
65c9bba85c feat(error): Provide kind()
This is prep for deprecating direct member access but not doing it yet.
2022-02-01 11:27:08 -06:00
Ed Page
7f61869a60 refactor: Reduce visibility on Error members 2022-02-01 11:27:08 -06:00
Jan Verbeek
bfc8e8d367 perf: Do not instantiate Id::from(&&str)
Saves 0.3K.
2022-02-01 17:22:03 +01:00
Jan Verbeek
9e625c0c55 perf: Avoid clone 2022-02-01 17:22:03 +01:00
Jan Verbeek
d1d9f75d53 perf: Make formatting method calls more efficient
If a value must be reused later then it's better to pass it as a &str
instead of cloning it, that means the clone happens in a central
place (inside the method).

By never passing a &String those instances of the method are not monomorphized.

Saves only 0.5K, maybe not worth it in hindsight.
2022-02-01 17:22:03 +01:00
Jan Verbeek
54e8f7eff2 perf: Extract common Error constructor logic
Saves 1.2K.
2022-02-01 17:21:57 +01:00
Jan Verbeek
b2cc41884d style: Use clearer variable name for formatted verb 2022-02-01 17:21:57 +01:00
Jan Verbeek
0dce4b5af2 perf: Split delimited value in single iterator
Saves 0.9K.
2022-02-01 17:21:52 +01:00
Jan Verbeek
9b03495bc6 perf: Format directly into strings
Saves 0.5K (and some allocations).
2022-02-01 17:21:52 +01:00
Jan Verbeek
4420fd25c8 perf: Merge .clone() calls
This seems like something rustc would be able to figure out, but
apparently not.

Saves 0.6K.
2022-02-01 17:21:52 +01:00
Jan Verbeek
6411e2ede6 style: Change format!("{}") → to_string() 2022-02-01 17:21:47 +01:00
Jan Verbeek
2d340dce9e perf: Prefer write_str() over write!("{}")
Saves 1K.
2022-02-01 17:21:47 +01:00
Jan Verbeek
778bcf2ecc perf: Extract non-generic part of App::new()
Saves 5K.
2022-02-01 17:21:47 +01:00
Jan Verbeek
7774a8ee8a perf: Do not clone subcommands
This saves a whopping 8K. I suspect it allows two sorting functions
to be merged.
2022-02-01 17:21:47 +01:00
Jan Verbeek
c77fb2e11d perf: Remove unnecessary clone 2022-02-01 17:21:47 +01:00
Jan Verbeek
14f9ec0ab6 style: Avoid nested unwrap_or 2022-02-01 17:21:47 +01:00
Jan Verbeek
14fa6a73fa perf: Avoid unnecessary String
Saves 0.3K.
2022-02-01 17:21:47 +01:00
Jan Verbeek
b4a2966e51 style: Convert char to string in single operation 2022-02-01 17:21:47 +01:00
Jan Verbeek
b5a8f828b8 style: Use if instead of strange Option::map_or 2022-02-01 17:21:47 +01:00
Jan Verbeek
21f0cd5662 perf: Avoid double reference 2022-02-01 17:21:47 +01:00
Jan Verbeek
0b3ad1735a perf: Avoid unnecessary copies in errors
Saves 3.5K.
2022-02-01 17:21:40 +01:00
Jan Verbeek
6d558c9141 perf: Do not inline get_color()
Saves 1.7K.
2022-02-01 17:21:40 +01:00
Jan Verbeek
3258396738 perf: Do not do verb formatting at runtime
Saves 1K.
2022-02-01 17:21:40 +01:00
Jan Verbeek
0c0d51b29a perf: De-inline another formatting method 2022-02-01 17:21:40 +01:00
Jan Verbeek
82dd01a1df style: Change unwrap_or_else() → or() 2022-02-01 17:21:35 +01:00
Jan Verbeek
29191bf386 perf: Remove another BTreeMap
This is smaller if we do a stable sort.
2022-02-01 00:02:44 +01:00
Jan Verbeek
844e0cde91 perf: Improve display_arg_val() code size
Making it non-generic doesn't seem to help.
2022-02-01 00:02:44 +01:00
Jan-Bernd Vosteen
c78494fd75 added missing 'be' 2022-01-31 14:52:36 +01:00
Wilfred Hughes
f7a2b472a2
Fix typo in doc comment 2022-01-29 16:18:33 -08:00
Jan Verbeek
a18658af86 perf: Replace BTreeMaps by manually sorted Vecs
This removes another ~20KB of code size.

There is one BTreeMap left, but replacing that one doesn't make a difference.
2022-01-29 22:18:32 +01:00
Jan Verbeek
7bf2479125 perf: Do not inline formatting methods
This shaves off ~20KB from the argparse-benchmarks-rs app.
2022-01-29 22:18:30 +01:00
Sondre Nilsen
0b045f5d0d
feat(man): Initial man generator (#3174)
This is an initial implementation with plenty of room to grow, including
- Allowing pulling out a subset of the generated man page for greater customization
- Subcommand handling
- Extra sections
- Consolidate argument formatter after #2914

Fixes #552
2022-01-28 14:55:55 -06:00
Ed Page
d2109b3969 chore: Release 2022-01-26 15:54:12 -06:00
Peter Grayson
7eea7d27ad
fix(help): Optional arg values in brackets
When an Arg uses .min_values(0), that arg's value(s) are effectively
optional. This is conventionaly denoted in help messages by wrapping the
arg's values in square brackets. For example:

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

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

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

We now track the highest precedence value for a group.

Fixes #3330
2022-01-24 10:34:41 -06:00
Ed Page
43673a1bd1 docs(error): Update reported failure code
Fixes #3332
2022-01-24 08:11:18 -06:00
Ed Page
5877f884f1 chore: Release 2022-01-18 14:59:58 -06:00
Ed Page
38e6952d46 fix: Don't panic when propagating
I thought I was adding a test in #3305.  Maybe I considered the
clap_complete changes sufficient for this.  Doing more `debug_assert`s
would be good also.

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

Fixes #3310
2022-01-18 14:38:58 -06:00
Ed Page
bd1bf66279 chore: Release 2022-01-17 20:34:09 -06:00
Rain
236ec973d9 feat: Implement App::find_subcommand_mut
Similar to `App::find_subcommand`, except it returns a mutable reference
to the subcommand.
2022-01-17 12:31:41 -08:00
Ed Page
ccbbba8908 chore: Release 2022-01-17 09:37:45 -06:00
Ed Page
ffe6bff8ac
Merge pull request #3305 from epage/help
fix(help): Always respect DisableColoredHelp
2022-01-17 09:35:18 -06:00
Ed Page
4a43b51a42 fix(complete): Handle help completions
The main motivation was to reduce special cases by putting all of the
logic in one place.
2022-01-17 09:23:04 -06:00
Ed Page
e962ad8ce6 fix(help): Always respect DisableColoredHelp
We might be able to handle version/help before propagation but I didn't
want to hold up this fix for that to happen and increase the risk
associated with this fix.

Fixes #3298
2022-01-17 09:14:07 -06:00
Ed Page
807ddbbb70 refactor: Build help subcommand separately 2022-01-17 08:36:37 -06:00
Ed Page
729f4e7e82 refactor: Make subcommand propagation reusable 2022-01-17 08:33:07 -06:00