Commit graph

6595 commits

Author SHA1 Message Date
Ed Page
2de59195aa fix!: Prefer IntoIterator over &[]
The main breakinge change cases:
- `&[char]`: now requires removing `&`
- All other non-ID `&[_]`: hopefully #1041 will make these non-breaking

Fixes #2870
2022-08-15 13:26:17 -05:00
Ed Page
dcfbee9787
Merge pull request #4080 from epage/iter
feat(parser): Report what arg ids are present
2022-08-15 11:15:30 -05:00
Ed Page
9c9cc9fcff docs(cookbook): Add position-sensitive example 2022-08-15 10:59:05 -05:00
Ed Page
7486a0b4b9 feat(parser): Report what arg ids are present
For now, we are focusing only on iterating over the argument ids and not
the values.

This provides a building block for more obscure use cases like iterating
over argument values, in order.  We are not providing it out of the box
at the moment both to not overly incentize a less common case, because
it would abstract away a performance hit, and because we want to let
people experiment with this and if a common path emerges we can consider
it then if there is enough users.

Fixes #1206
2022-08-15 10:00:42 -05:00
Ed Page
c45bd64941 test(builder): Clear up test files names 2022-08-15 09:47:49 -05:00
Ed Page
495e49e1a7
Merge pull request #4075 from cnpryer/faq
Quality improvements to FAQ docs
2022-08-13 21:58:30 -05:00
Ed Page
fb9dca0a0c
Merge pull request #4076 from cnpryer/tutorial-builder
Fix enum example comment
2022-08-13 21:51:15 -05:00
Chris Pryer
8bf39d9275
docs(tutorial): Fix enum example comment 2022-08-13 20:56:27 -04:00
Chris Pryer
ec55eb6a20
docs: Quality improvements to FAQ docs 2022-08-13 19:32:03 -04:00
Ed Page
69e1e431e9 fix: Publicly expose 'Values' iterator 2022-08-12 17:05:02 -05:00
Ed Page
3c82418c8c
Merge pull request #4072 from epage/group
fix(parser)!: Store args in a group, rather than values
2022-08-12 17:00:49 -05:00
Ed Page
41be1bed08 fix(parser)!: Store args in a group, rather than values
Now that `Id` is public, we can have `ArgMatches` report them.  If we
have to choose one behavior, this is more universal.  The user can still
look up the values, this works with groups whose args have different
types, and this allows people to make decisions off of it when otherwise
there isn't enogh information.

Fixes #2317
Fixes #3748
2022-08-12 16:40:07 -05:00
Ed Page
004de00771 feat: Publicly expose Id 2022-08-12 16:25:47 -05:00
Ed Page
43ca9a2547 perf: Track static strs for Id
Unfortunately, this added another 6.6 KB

Compared to `HEAD~` on `06_rustup`:
- build: 7.41us -> 6.28us
- parse: 9.36us -> 8.07us
- parse_sc: 9.29us -> 7.74us

For context, this run compares `HEAD` to `v3-master`
```
build_rustup            time:   [10.765 µs 10.869 µs 10.981 µs]
                        change: [+72.716% +74.316% +75.832%] (p = 0.00 < 0.05)
                        Performance has regressed.
parse_rustup            time:   [14.264 µs 14.329 µs 14.407 µs]
                        change: [+75.565% +76.899% +78.172%] (p = 0.00 < 0.05)
                        Performance has regressed.
parse_rustup_with_sc    time:   [14.947 µs 15.025 µs 15.107 µs]
                        change: [+92.606% +94.079% +95.573%] (p = 0.00 < 0.05)
                        Performance has regressed.
```
So anything we are doing at this point is a large improvement.
2022-08-12 16:07:41 -05:00
Ed Page
5b5f2c1f40 fix!: Track original Ids, rather than a hash
This is a step towards #1041
- `ArgGroup` no longer takes a lifetime
- One less field type needs a lifetime

For now, we are using a more brute force type (`String`) so we can
establish performance base lines.  I was torn on whether to use `&str`
everywhere or make an `IdRef`.  The latter would add a lot of noise that
I'm concerned about, so i left it simple for now.  `IdRef` would help to
communicate the types involved though.

Speaking of communicating types, I'm also torn on whether we should use
`Id` for all strings or if we should have `Id`, `Name`, etc types to
avoid people mixing and matching.

This added 18.7 KB.

Compared to `HEAD~` on `06_rustup`:
- build: 6.23us -> 7.41us
- parse: 8.17us -> 9.36us
- parse_sc: 7.65us -> 9.29us
2022-08-12 15:46:04 -05:00
Ed Page
f84e38a4de fix!: Switch from &[] to IntoIterator
This is a part of #2870 and is prep for #1041

Oddly enough, this dropped the binary size by 200 Bytes

Compared to `HEAD~` on `06_rustup`:
- build: 6.21us -> 6.23us
- parse: 7.55us -> 8.17us
- parse_sc: 7.95us -> 7.65us
2022-08-12 15:45:02 -05:00
Ed Page
96f91ca092 refactor(assert): Make it easier to change id type
Compared to `master` on `06_rustup`:
- build: 5.74us -> 6.21us
- parse: 7.57us -> 7.55us
- parse_sc: 7.60us -> 7.95us
2022-08-12 15:43:22 -05:00
Ed Page
426a7d20f3 fix(debug): Clean up debug message 2022-08-12 13:06:09 -05:00
Ed Page
f1b86a6ae4 refactor(parser): Don't hide allocation 2022-08-12 13:04:48 -05:00
Ed Page
1849d566d2 refactor(assert): Remove dead code 2022-08-12 12:54:30 -05:00
Ed Page
ca046aaa01 refactor: Abstract away name's access
This is prep for merging name/id
2022-08-12 12:50:04 -05:00
Ed Page
d7735d5cf2 refactor: Move commands off of Id
This is prep for changing out the types

This dropped the size by 0.4 KB
2022-08-12 10:35:49 -05:00
Ed Page
a5494573af chore(ci): Lock docs to MSRV
This will help avoid issues with new warnings
2022-08-12 08:24:15 -05:00
Ed Page
14b70597c0
Merge pull request #4067 from epage/clippy
style: Address clippy
2022-08-12 08:22:57 -05:00
Ed Page
43e961d24f style: Address clippy 2022-08-11 16:07:58 -05:00
Ed Page
084a6dffeb
Merge pull request #4065 from epage/flat
refactor: Move off of HashMap/IndexMap to flat containers
2022-08-11 14:47:54 -05:00
Ed Page
e7ced880e2 docs: Fix for 1.63 2022-08-11 14:31:31 -05:00
Ed Page
6e7fd6d4bc refactor: Move off of IndexMap/HashMap
This dropped 17KB

Again, performance shouldn't be too bad as the total number of argument
id's passed in by the user shouldn't be huge, with the upper end being
5-15 except for in extreme cases like rustc accepting arguments from
cargo via a file.
2022-08-11 14:06:41 -05:00
Ed Page
d441ebbf62 refactor: Move off of IndexSet/HashSet
This dropped `.text` by 14KB

Anything in debug asserts or help/usage output doesn't matter for
performance but I wouldn't be surprised if this was comparable since the
container sizes we are talking about are relatively small.
2022-08-11 14:03:28 -05:00
Ed Page
b344f1cf18
Merge pull request #4060 from epage/msrv
chore: Bump MSRV to 1.60.0
2022-08-11 09:06:56 -05:00
Ed Page
1c06735390 chore: Update dependencies 2022-08-10 21:49:22 -05:00
Ed Page
6bc8dfd32b
Merge pull request #4059 from epage/no-implicit
fix: No implicit version/help actions
2022-08-10 21:48:07 -05:00
Ed Page
3390adf0d3 chore: Bump MSRV to 1.60.0
While at it, this cleans up all of the features.  For some reason, I
couldn't do `dep:clap_derive` though.
2022-08-10 21:32:06 -05:00
Ed Page
07b6e66eb7 fix: No implicit version/help actions
Documenting the existing behavior is challenging which suggests it can
cause user confusion.  So long as its not too hard to explicitly
specify actions, we should just do it.

Fixes #4057
2022-08-10 21:21:53 -05:00
Ed Page
1a08b9184b
Merge pull request #4056 from epage/help
fix!: Require explicit help/version disabling
2022-08-10 20:46:51 -05:00
Ed Page
f70ebe89a7 fix!: Require explicit help/version disabling
Before we introduced actions, it required specific setups to engage with
claps version and help printing.  With actions making that more
explicit, we don't get as much benefit from our multiple, obscure, ways
of users customizing help

Before
- Modify existing help or version with `mut_arg` which would
  automatically be pushed down the command tree like `global(true)`
- Create an new help or version and have it treated as if it was the
  built-in on (I think)
- Use the same flags as built-in and have the built-in flags
  automatically disabled
- Users could explicitly disable the built-in functionality and do what
  they want

Now
- `mut_arg` no longer works as we define help and version flags at the
  end
- If someone defines a flag that overlaps with the built-ins by id,
  long, or short, a debug assert will tell them to explicitly disable
  the built-in
- Any customization has to be done by a user providing their own.  To
  propagate through the command tree, they need to set `global(true)`.

Benefits
- Hopefully, this makes it less confusing on how to override help
  behavior.  Someone creates an arg and we then tell them how to disable
  the built-in
- This greatly simplifies the arg handling by pushing more
  responsibility onto the developer in what are hopefully just corner
  cases
- This removes about 1Kb from .text

Fixes #3405
Fixes #4033
2022-08-10 20:33:21 -05:00
Ed Page
0129d99f4c
Merge pull request #4055 from epage/clippy
style: Make clippy happy
2022-08-10 11:57:09 -05:00
Ed Page
64639aa81c style: Make clippy happy 2022-08-10 11:41:27 -05:00
Ed Page
c7d9fec2f8
Merge pull request #4054 from epage/help
fix(debug): Make it easier to address help issues
2022-08-10 09:30:04 -05:00
Ed Page
ac9f4727e0 fix(debug): Make it easier to address help issues
Inspired by #4033
2022-08-10 09:15:15 -05:00
Ed Page
9006f9a716
Merge pull request #4050 from epage/docs
docs: Clarify confusing API points
2022-08-09 16:48:29 -05:00
Ed Page
22c82c7404 docs(tutorial): Further expand on actions 2022-08-09 16:33:02 -05:00
Ed Page
a98bcb4d13
Merge pull request #4049 from danielparks/issue-3785-derive-id-attr
fix(derive): Add "id" attribute
2022-08-09 14:31:45 -05:00
Daniel Parks
1a2ae76738
fix(derive): Add "id" attribute
Previously the Arg id was set with the "name" attribute. This allows use
of an "id" attribute to match the underlying struct.

A side effect of this is that the "id" attribute may also be used on
Commands. This isn't desired, but given the current architecture of the
attribute parser, it's hard to avoid.

Fixes: #3785
2022-08-09 12:15:02 -07:00
Ed Page
6aa4f90609
Merge pull request #4045 from epage/enum
docs(tutorial): Switch to hand-implemented ValueEnum
2022-08-09 11:30:23 -05:00
Ed Page
2d352cb16f docs: Clarify intention for new APIs 2022-08-09 10:23:23 -05:00
Ed Page
36777e7b6c docs(tutorial): Switch to hand-implemented ValueEnum 2022-08-09 10:23:23 -05:00
Ed Page
1c3159700d docs(contrib): Say why we use feature flag 2022-08-09 10:23:23 -05:00
Ed Page
78b2b44b95 docs(tutorial): Focus on actions, not macros 2022-08-09 10:23:23 -05:00
Ed Page
52f039e549
Merge pull request #4044 from epage/v4
docs: v4-specific improvements
2022-08-08 20:47:04 -05:00