Commit graph

3117 commits

Author SHA1 Message Date
Ed Page
8f45d2f95a docs(derive): Reword opt-out 2023-03-28 08:34:29 -05:00
Ed Page
06d190751a docs(derive): Clarify opt-out of special type behavior
Inspired by #4808
2023-03-28 08:13:28 -05:00
Ed Page
56fe5e0ec0 fix!: Remove unstable-replace feature flag
This has been implemented for 3 years without much traction for
finishing it up.

The subcommand use case can be worked around by creating `Command`s that
just include the relevant logic, very similar to the default subcommand
examples in `git` / `git-derive`.

Using this for flags is covered by #4793.

Without `unstable-replace` being enabled, this still cut 5 KiB from
`cargo bloat --release --example git`.

Closes #2836
Closes #2011
2023-03-28 00:26:45 -05:00
Kurtis Nusbaum
5430df7a0f feat(derive): Support #[group] attributes
This adds the ability derive additional options for the group creation.

Fixes #4574
2023-03-25 03:25:38 -05:00
Ed Page
4e1a565b8a refactor: Split out clap_builder for faster derive builds
For now, we are still treating `clap` as the user facing API for both
builder and derive, making this an internal change as we don't expect
this to negatively impact builder build times all that much.  We can
re-evaluate at a later time and consider having distinct top-level
crates for builder and derive.

Looking at `--timings` on my machine
- `clap` only took 0.04s to build and it happened in
  parallel to `clap_builder` codegen
- this saved 1.7s for derive build times, with `clap_builder` building
  in parallel to `syn` and `clap_builder` and `clap_derive` finishing
  around the same time.

This was discussed some at https://rust-lang.zulipchat.com/#narrow/stream/220302-wg-cli/topic/clap.20build.20times.20and.20.60clap_derive.60.3A.20a.20crazy.20idea
2023-03-24 21:50:02 -05:00
Ed Page
5b65ede0ae style: Reduce unstable-v5 warnings 2023-03-24 21:32:58 -05:00
Ed Page
5d0fbb47ce doc: Clean up cfgs 2023-03-24 21:32:58 -05:00
Ed Page
f04ad2f38c
Merge pull request #4779 from epage/reserve
perf: Reduce alloc calls when building
2023-03-23 15:43:33 -05:00
Ed Page
a62fd05d53 perf: Reduce alloc calls when building
Inspired by #4774
2023-03-18 11:59:01 -05:00
Ed Page
769ccc5cd6 Revert "chore: Update bitflags dep to 2.0"
This reverts commit 6878a1911b.
2023-03-18 11:48:04 -05:00
Ed Page
cc1474f97c docs(help): Remove stale reference about wrapping
Fixes #4772
2023-03-17 00:16:13 -05:00
Nicholas Bishop
6878a1911b chore: Update bitflags dep to 2.0 2023-03-18 12:35:17 -04:00
Ed Page
fcd6a65e18 fix(help): Don't style newlines
Windows will style all blank space until the end of line (sometimes).

Fixes #4431
2023-03-16 18:59:54 -05:00
Ed Page
c0dc1cd008 fix(parser): Clarify get_count/get_flag assertion
Fixes #4763
2023-03-16 10:23:34 -05:00
Ed Page
6e1e754aa8 docs: Update docs for derived display order
Fixes #4728
2023-02-24 07:34:17 -06:00
Martin Fischer
8c92ef6c76
fix(help): Fix yet another --help long help edge case (#4712) 2023-02-15 11:33:35 -06:00
Martin Fischer
473cf175a2
fix(help): Fix --help help text in edge case (#4710)
We were accidentally showing long help just because a hidden argument had a description for a possible value.  This is most likely to be hit with the derive API as the value descriptions are automatically applied from documentation.
2023-02-15 10:25:19 -06:00
Aleksander Krauze
d6e7d4699f Improve builder::str::inner::Inner::into_string implementation
Since `Inner::into_string` already takes ownership of `self` we can
avoid unnecessary copy and allocation by moving `Box<str>` and using
its implementation of `Into<String>`.
2023-02-15 16:16:14 +01:00
Martin
704d0e7a4f chore: Make format!() calls more readable 2023-01-29 19:14:47 +00:00
Ed Page
6e5e31a02c docs(tutorial): Clarify use of Append in derive 2023-01-27 15:24:35 -06:00
Ed Page
7c4c6586d0
Merge pull request #4673 from epage/arg
perf: Speed up compiling `arg!` macro
2023-01-24 16:40:50 -06:00
Ed Page
bbe5eaa709 perf: Speed up compiling arg! macro
To "append" calls, we were passing in a more and more complex expression
on each recursive invocation.  We now pass in a fixed amount of data on
each iteration, reducing how much the macro machinery needs to parse,
speeding up builds.

Fresh builds went from 39s to 32s on my machine.

Inspired by #4670
2023-01-24 16:23:44 -06:00
Ed Page
dc89379ff6 fix(help): Respect disable_colored_help for arg_required_else_help
Fixes #4671
2023-01-24 15:53:00 -06:00
Ed Page
125dbe0cfd
Merge pull request #4667 from corneliusroemer/fix-4666
fix: Add plural s to context in suggestions
2023-01-23 15:58:37 -06:00
Cornelius Roemer
f5540d2646 fix(suggestions): Replace wrong Jaro-Winkler
Implementation of Jaro-Winkler similarity in the dguo/strsim-rs crate
is wrong, causing strings with common prefix >=10
to all be considered perfect matches

Using Jaro instead from the same crate fixes this issue
Benefit of favoring long prefixes exists for matching common names
But not for typo detection
Hence use of Jaro instead of Jaro-Winkler is acceptable

Confidence threshold adjusted so that `bar` is still suggested for `baz`
since Jaro is strictly < Jaro-Winkler
such an adjustment is expected. This is acceptable.
While exact suggestions may change, the net change will be positive
Suggestions are purely decorative and should thus not breaking change

Fixes #4660
Also see https://github.com/dguo/strsim-rs/issues/53
2023-01-23 22:43:48 +01:00
Cornelius Roemer
5dcc5c9509 fix: Add plural s in suggestions
Old: `note: subcommand 'test', 'temp' exist`
New: `note: subcommands 'test', 'temp' exist`
Fixes #4666
2023-01-23 22:16:50 +01:00
Ed Page
3591dc7e84 test: Remove extraneous to_owned's 2023-01-23 10:33:47 -06:00
Ed Page
cf970e6d0e test: Very best-fit for suggestions
Inspired by #4660
2023-01-23 09:58:03 -06:00
Ed Page
39fc252196 test: Re-enable suggestion tests 2023-01-23 09:55:14 -06:00
Ed Page
a493bb54f4
Merge pull request #4659 from epage/flag
docs: Prefer `get_flag` over `get_one::<bool>`
2023-01-23 09:36:21 -06:00
Ed Page
9d1de20787 docs: Prefer get_flag over get_one::<bool>
Inspired by #4654
2023-01-23 09:23:38 -06:00
Maria José Solano
bbf9b9c2f5
docs: Typo in tab tag 2023-01-14 13:05:17 -08:00
Ed Page
162a556dba fix(error): Try to soften unexpected argument/value errors
Adding "found" might seem minor but I feel it has a slight softening on the message.  It also maintains scanability as it is at the end and short.

As this is a one-off message change and not a styling issue to be consistent with, I think this is safe to put in a patch release.
2023-01-13 21:29:49 -06:00
Ed Page
523adc20e7
Merge pull request #4635 from epage/stablize
feat: Stablize `ArgMatches::get_occurrences`
2023-01-13 06:52:30 -06:00
Ed Page
b4f111a978 feat: Stablize ArgMatches::get_occurrences
This let's you get an arguments values, grouped by the occurrence of the
argument.

Note: this does not stablize derive support.  That requires a blocking
change and can be enabled via `unstable-v5` flag.  See #4626 for an
exploration of how we can make this easier in the future.

Fixes #2924
2023-01-12 21:37:19 -06:00
Ed Page
5345d6c332
Merge pull request #4625 from rhysd/fix-is-is
fix(doc): Fix typos in document of `ArgMatches` methods
2023-01-10 19:55:46 -06:00
rhysd
4b1f79b470 fix(doc): Fix typos in ArgMatches methods 2023-01-11 10:46:44 +09:00
David Aguilar
0b0306cc79 feat(api): Add Arg::get_value_terminator()
Expose get_value_terminator() for use by clap_complete.

Related-to: #3022
Signed-off-by: David Aguilar <davvid@gmail.com>
2023-01-10 00:38:56 -08:00
Ed Page
9aa76fa12f docs: Update changelog 2023-01-09 14:03:47 -06:00
Ed Page
082d54a9dc style: Update for clippy 1.64 2023-01-09 12:38:55 -06:00
Ed Page
f25fe5b3e0 chore: Bump MSRV to 1.64.0 2023-01-09 12:29:41 -06:00
Trevor Gross
c062182e1e docs: fix example that as runtime panic. Relates to #3864
Relevant comment: https://github.com/clap-rs/clap/issues/3864#issuecomment-1374297155
2023-01-06 19:24:12 -05:00
Ed Page
762b06fba4 fix(error): Try to polish/clarify messages
In text communication you need to balance
- Scannability, putting the most important information upfront
- Brevity so people don't get lost in the message
- Softness to help ease people through a frustrating experience

I feel we weren't doing great on the first two points, so tried to
iterate on the messages to improve them.  I hope we aren't suffering too
much on the third point as a side effect.
2023-01-06 17:01:36 -06:00
Ed Page
68a7740fdc fix(error): Match rustc for giving more information 2023-01-03 13:22:35 -06:00
Ed Page
c2efb60a5f fix(error): Lowercase the start of error messages
This matches the rustc error style
2023-01-03 13:17:46 -06:00
Ed Page
e7d58b3daf
Merge pull request #4385 from epage/errors
fix(error): Be consistent with rustc diagnostic guidelines
2023-01-03 12:54:16 -06:00
Ed Page
7229047d78
Merge pull request #4514 from noritada/notes-on-cargo-env-vars
docs: Present other environment variable alternatives to `crate_name!`
2023-01-03 12:44:42 -06:00
Ed Page
36bc641648 fix(help): Remove extraneous text from built-ins
This is an intermediate solution for #4408.  As there were no agreeed
upon goals, I went with what I felt read well and that I saw commonly
used on non-clap commands.

- "information" isn't really a necessary word.
- I originally favored `Print this help` but realied that doesn't read
  correctly in completions.
- Besides being shorter, the reason for the flipped short/long hint is
  it gives people the context they need for scanning, emphasizing
  "summary" and "more".

Fixes #4409
2023-01-03 11:02:26 -06:00
Ed Page
a87b55900d doc(derive): Clarify default_value_t reqs
Fixes #4599
2023-01-02 22:37:24 -06:00
Ed Page
85ecb3e895 fix(parser): Override required when parent group has conflict
Fixes #4569
2022-12-22 13:09:14 -06:00