Commit graph

5356 commits

Author SHA1 Message Date
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
7ca872e7bb
Merge pull request #3395 from epage/box
refactor: Prepare for replacing `info`
2022-02-02 15:59:20 -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
6638fc4e2d
Merge pull request #3394 from epage/possible
feat(error): Show possible values when none are supplied
2022-02-02 14:49:36 -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
d4cfceedab
Merge pull request #3391 from epage/possible
fix(error): Consistently respect possible values order
2022-02-02 14:11:19 -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
7c79e76f2f
Merge pull request #3390 from epage/unroll
fix(error): Be more accurate in smart usage
2022-02-02 13:53: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
d318752cac docs(derive): Expand on parse attribute 2022-02-02 10:37:47 -06:00
Ed Page
b4adda3284
Merge pull request #3385 from epage/pred
refactor: Clarify intent behind requires
2022-02-01 18:30:44 -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
f6005052a9
Merge pull request #3384 from epage/pred
refactor: Clarify intent of default_value_if
2022-02-01 16:50:14 -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
6fa8113168 docs: Update changelog 2022-02-01 16:10:44 -06:00
Ed Page
8e807c2043
Merge pull request #3382 from epage/matches
feat(parser): Check if args were present
2022-02-01 16:06:59 -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
8efee8a671
Merge pull request #3381 from epage/parser
refactor: Minor progress on reducing Parser's visibility
2022-02-01 14:21:09 -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
ad88462687
Merge pull request #3380 from epage/vis
refactor: Avoid direct member access
2022-02-01 11:54:18 -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
Ed Page
ba582e77b0
Merge pull request #3378 from blyxxyz/size
Optimize code size further
2022-02-01 11:13:18 -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