Commit graph

5083 commits

Author SHA1 Message Date
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
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
Ed Page
96dbbad785
Merge pull request #3376 from MForster/update-readme
Update README.md to match example code
2022-02-01 06:58:50 -06:00
Ed Page
7f812618a6
Merge pull request #3375 from rfdonnelly/fix-bool-parsing-link
Update link to explicit bool parser example
2022-02-01 06:58:24 -06:00
Ed Page
a22ef919c4
Merge pull request #3374 from rfdonnelly/fix-faq-toc
Fix FAQ table of contents
2022-02-01 06:57:39 -06:00
Ed Page
23fd8d3e26
Merge pull request #3377 from clap-rs/dependabot/cargo/trycmd-0.12
chore(deps): update trycmd requirement from 0.9 to 0.12
2022-02-01 06:56:40 -06:00
dependabot[bot]
55ac69827b
chore(deps): update trycmd requirement from 0.9 to 0.12
Updates the requirements on [trycmd](https://github.com/assert-rs/trycmd) to permit the latest version.
- [Release notes](https://github.com/assert-rs/trycmd/releases)
- [Changelog](https://github.com/assert-rs/trycmd/blob/main/CHANGELOG.md)
- [Commits](https://github.com/assert-rs/trycmd/compare/v0.9.0...v0.12.2)

---
updated-dependencies:
- dependency-name: trycmd
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-01 07:04:59 +00:00
Michael Forster
d81110b5c5 docs: Update README.md to match example code 2022-02-01 07:35:16 +01:00
Rob Donnelly
c8bb8def57 docs(faq): Fix table of contents
* Remove entries for sections that no longer exist
* Update entry for "How many approaches"
* Renumber entries
2022-01-31 22:01:34 -08:00
Rob Donnelly
a19bca8a10 docs(error): Update link to explicit bool parser example 2022-01-31 21:58:54 -08: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
Ed Page
38e7ec5c33
Merge pull request #3372 from NeuralNetwork/master
added missing 'be'
2022-01-31 10:24:36 -06:00
Jan-Bernd Vosteen
c78494fd75 added missing 'be' 2022-01-31 14:52:36 +01:00