Commit graph

3134 commits

Author SHA1 Message Date
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
Ed Page
dcd5fecab0
Merge pull request #4572 from epage/group
perf(parser): Reduce lookups for conflicts
2022-12-22 12:38:29 -06:00
Ed Page
dde22e74ca style: Update for latest clippy 2022-12-22 12:25:33 -06:00
Ed Page
dd8435d8f3 perf(parser): Reduce duplicate lookups
Didn't actually see much of a gain because this isn't in a hot loop but
thought I'd keep it.
2022-12-22 12:17:24 -06:00
Ed Page
4a34b9dd43 perf(parser): Reduce lookups for conflicts
We already need to lookup every present-arg for conflicts, so we might
as well cache it ahead of time.  This let's us move some operations to
be immutable so we can more easily cache other lookups.

For me, this gave a 70% speed improvement for #4516 with mixed results
on normal benchmarks
2022-12-22 12:16:37 -06:00
Ed Page
9242e1dd00
Merge pull request #4566 from hitenkoku/fix/4565
removed {bin} variable from help_template
2022-12-22 10:33:22 -06:00
DastInDark
b72ad5892c fix: Added cfg in help_template 2022-12-22 01:38:49 +09:00
DastInDark
c6058dee6e fix(help_template): Added cfg 2022-12-22 01:13:20 +09:00
DastInDark
a7a8241487 docs(command): Added deprecated suffix in help string 2022-12-22 01:13:20 +09:00
DastInDark
a42204243a fix(help_template): Remove {bin} variable 2022-12-22 01:13:02 +09:00
Thayne McCombs
6abc2cfc3b feat: Add get/remove API for getting grouped values
Change it to be more consistent with get_one and get_many and related
functions.

Relates-To: #2924
2022-12-20 22:50:03 -07:00
Ed Page
453ac0bfb9 fix(parser): Be less confusing with args/subcommand conflicts
The new error message still isn't great but its better than the old one.

Reported at https://hachyderm.io/@eminence/109548978776785113
2022-12-20 20:27:58 -06:00
Ed Page
a72f962d35 docs(builder): Escape non-tags 2022-12-20 07:55:04 -06:00
Ed Page
ac48e2d5e4 docs: Make less brittle for rust versions 2022-12-20 07:54:30 -06:00
Ed Page
aa5420469e
Merge pull request #4555 from epage/reset
docs: Clarify role of Resettable
2022-12-14 21:04:29 -06:00
Ed Page
16c499c7b3 docs: Clarify role of StyledStr 2022-12-14 19:29:01 -06:00
Ed Page
1f3d5a321f docs: Clarify role of Resettable
Inspired by #4554
2022-12-14 19:21:08 -06:00
Dezhi Wu
577b7f24fa docs: Fix a typo 2022-12-14 15:47:15 +08:00
Ed Page
bf39b8d280 docs(ref): Move flatten/subcommand to be under command attr
Fixes #4505
2022-11-28 09:49:15 -06:00
Noritada Kobayashi
e2501ef7c2 docs: Present environment variable alternatives to crate_name!
`crate_name!` macro uses a value of an environment variable
`CARGO_PKG_NAME`, but there are other similar variables
`CARGO_PKG_NAME` and `CARGO_CRATE_NAME`, that users should be aware of.
2022-11-27 23:43:59 +09:00
Ed Page
20e02eb34e
Merge pull request #4509 from epage/possible
feat: Improve ValueParser experience
2022-11-24 10:06:52 -06:00
Ed Page
fb1d960fe2
Merge pull request #4249 from jcgruenhage/replace-atty
chore: replace atty with is-terminal
2022-11-24 09:48:37 -06:00
Ed Page
94aca92e44 feat: Create ValueParser from Vec<PossibleValue>
This dynamically generated list of possible values.  Inspired by #4504
2022-11-24 09:47:33 -06:00
Ed Page
3bccfced1a docs: Clarify PossibleValue is likely not needed
Fixes #4504
2022-11-24 09:47:33 -06:00
Ed Page
19981a2455 docs: Clarify ColorChoice impls ValueEnum 2022-11-24 09:47:33 -06:00
Ed Page
8d92f3e7a8 feat: Add Display/FromStr to ColorChoice
This matches up with `clap_complete::Shell`.  This makes it a bit more flexible.
2022-11-24 09:47:33 -06:00
Ed Page
ed683ef248 fix: Always expose ColorChoice 2022-11-24 09:47:33 -06:00
Jan Christian Grünhage
aaac3c4930
chore: Replace atty with is-terminal 2022-11-24 15:33:43 +01:00
Ed Page
623ccbc152 style: Make clippy happy 2022-11-24 08:05:21 -06:00
Alex Saveau
fd64c8ae93
Gate term_width and max_term_width APIs on wrap_help 2022-11-20 19:33:02 -08:00
Ed Page
44dd8ea4c5 fix: Correctly refer to unstable-v5 2022-11-17 10:09:45 -06:00
Ed Page
dd143eed47 fix: Make ArgPredicate non_exhaustive in v5
Didn't want to forget to do this

Inspired by #4487
2022-11-17 09:01:51 -06:00
Peter Grayson
d9c9c7bdd8
fix: ContextKind.as_str() spellings
Signed-off-by: Peter Grayson <pete@jpgrayson.net>
2022-11-16 11:14:54 -05:00
Ed Page
6b62c82fe2 feat(parser): Show available subcommands when one is missing
Similar to
- Listing all required arguments when one is missing
- Listing all possible values when no value is provided

This came up when discussing #3572
2022-11-15 10:18:24 -06:00
Ed Page
c939de8a25 fix: Don't panic on non-built arg rendering
For num_args, we'll just use the default

Fixes #4479
2022-11-14 12:13:18 -06:00
Ed Page
e9cbed34cd fix(parser): Don't panic on invalid UTF-8 values
Fixes #4473
2022-11-11 12:26:04 -06:00
Ed Page
9376a57d40 fix(help): Clarify that 'help' command accepts multiple
Making this plural can go either way as
- Clarify it is plural
- This is all really to simulate actually doing subcommands and you only
  do one at a time

For now, I lean towards clarifying it is plural

I also tweaked the message to be more consistent with how `--help` and
`-h` describe themselves.

Fixes #4342
2022-11-07 23:04:04 -06:00
Ed Page
dfe9e73880 fix(help): Update auto-next-line to use new padding
In clap v4, we changed the padding from 4 to 2 but we didn't update our
calculation for when to switch to next-line-help as it was a magic
number (we tried to catch all of these).

When updating the tests, we also missed that a test was being wrapped
too narrowly

This was found while discussing #3300
2022-11-07 10:36:51 -06:00
Ed Page
539577dfb2 refactor(help): Remove dead code
`longest` is always the same or longer than the `sc_str.display_width`
2022-11-07 10:27:17 -06:00
Ed Page
c37ab6c205 fix(derive): Allow 'long_help' to force populating from doc comment
Fixes #4441
2022-11-07 09:41:52 -06:00
Thayne McCombs
2ff3d43724 feat(derive): Implement ValueEnum for ColorChoice 2022-11-04 00:29:52 -06:00
Ed Page
e11afa284b
Merge pull request #4401 from epage/last
fix(complete): Support last(true) with CommandWithArguments
2022-10-18 07:41:02 -05:00
Ed Page
1ead5ef421 fix(complete): Support last(true) with CommandWithArguments
Fixes #4400
2022-10-18 07:28:52 -05:00
Justin Browne
a1d4476f24 Fix a broken link in ValueEnum docs 2022-10-18 05:03:58 -04:00
Ed Page
45dcf0ed22 fix(parser): Don't make Args exclusive with their ArgGroup
This is most obvious with the derive API as it creates `ArgGroup`s all
over the place now.

Fixes #4396
2022-10-17 19:02:39 -05:00
Ed Page
f1ffc63a79 fix(error): Be consistent with rustc diagnostic guidelines
From
https://rustc-dev-guide.rust-lang.org/diagnostics.html#suggestion-style-guide

> Suggestions should not be a question. In particular, language like
> "did you mean" should be avoided. Sometimes, it's unclear why a
> particular suggestion is being made. In these cases, it's better to be
> upfront about what the suggestion is.
>
> The message may contain further instruction such as "to do xyz, use"
> or "to do xyz, use abc".

Inspired by #2766
2022-10-13 14:01:49 -05:00
Ed Page
0f3c98a799 fix(error): Be consistent in puncutation 2022-10-13 13:56:58 -05:00
Ed Page
b9d298086c refactor(error): Move subcommand suggestion to general suggestions 2022-10-13 13:17:44 -05:00
Ed Page
63eec40652 refactor(error): Clarify distinct suggestion cases 2022-10-13 13:15:11 -05:00
Ed Page
5275660967 refactor(error): Move escape suggestion to general suggestion 2022-10-13 13:10:15 -05:00
Ed Page
813060ea82 refactor(error): Move bad-escape suggestion to general suggestion 2022-10-13 13:03:14 -05:00
Ed Page
7417c75c57 refactor(error): Move escaped-subcmd suggestion to general suggestions 2022-10-13 12:59:13 -05:00
Ed Page
c8cb5bba38 feat(error): General suggestion mechanism 2022-10-13 12:20:04 -05:00
Ed Page
4ec79b1448 refactor(error): Centralize suggestions 2022-10-13 12:12:03 -05:00
Ed Page
a4bcba6840 fix(error): Consistently indent suggestions 2022-10-13 12:10:13 -05:00
Ed Page
47704314b1 refactor(error): Consolidate 'did you mean' code 2022-10-13 11:11:17 -05:00
Ed Page
a964f45b1b fix(error): Properly quote, color subcommand suggestions 2022-10-13 10:51:17 -05:00
Ed Page
1039c61c53 fix(error): Be more consistent in error quoting 2022-10-13 10:45:38 -05:00
Ed Page
f8053fcedb fix(error): Don't suggest '--' when it doesn't help 2022-10-13 10:17:11 -05:00
Ed Page
06e2388972 docs: Clarify default_values_ifs tuple parameters
Fixes #4376
2022-10-12 14:11:40 -05:00
Ed Page
d0dcaac2ab fix(parser): Only add ArgGroup to ArgMatches for command-line
This will fix `clap_derive`s behavior for optional-flattened groups as
it will properly detect when the group is present (#3566).

While I consider this a bug and not part of compatibility guarentees, I
still want to keep in mind user impact which could still prevent this.
Defaults will make the group always-present which has little value and
if anything is relying on this, it is probably an application bug.
2022-10-12 07:52:07 -05:00
Ed Page
e98fc7f6eb refactor(parser): Centralize knowledge for explicit 2022-10-12 07:46:39 -05:00
Ed Page
e704adb4ff refactor(parser): Centralize group handling
Since groups are only associated with the occurrence, we can move the
assigning of it to the occurrence start.

This will help centralize other checks
2022-10-12 07:37:41 -05:00
Ed Page
0f30ac76f1 refactor(parser): Remove function wrappers 2022-10-12 07:32:21 -05:00
Ed Page
8cf6d116e3 refactor(parser): Reduce code duplication 2022-10-12 07:31:09 -05:00
Ed Page
84828e8da9 refactor(parser): Remove function wrappers 2022-10-12 07:28:57 -05:00
Ed Page
43c1fa30d0 refactor(parser): Reduce code duplication 2022-10-12 07:26:30 -05:00
Ed Page
b26c01aa0e feat(derive): Allow type-less fields
When overriding other fields, help or version flag, globals, etc, a user
might not care about the value, so let's ignore the lookup.

Been talking about this for a while but Issue #4367 moved this forward
because there wasn't a good way to handle this without changing
behavior.
2022-10-11 10:31:42 -05:00
Ed Page
2122e2b2dd feat(parser): Add TypedValueParser::try_map
This is a major building block to avoid needing to implement
`TypedValueParser`

Inspired by #4362
2022-10-10 10:54:12 -05:00
Ed Page
502bb93e5b feat(error): Allow reproducing clap's errors
Fixes #4362
2022-10-10 10:25:36 -05:00
Ed Page
5b763e957c docs: Fix value_parser documented From types 2022-10-10 09:00:24 -05:00
Ed Page
a482b8a87b
Merge pull request #4355 from LingMan/patch-1
docs: Fix formatting in docs of value_parser! macro
2022-10-08 20:33:24 -05:00
Ed Page
fd41141071 docs: Clarify args_override_self
Fixes #4357
2022-10-08 20:18:27 -05:00
Ed Page
59bf166183 docs(tutorial): Fix flag actions
Fixes #4359
2022-10-08 20:14:03 -05:00
Harald Gutmann
505f760df9 fix(clap): Early line wrap ascii control chars
counting ascii control sequences lead to unpredictable and early
line breaks on colorized inputs (e.g. syntax highlighted strings)
2022-10-08 19:55:52 +02:00
Harald Gutmann
95c638842a fix(clap): Early line wrap ascii control chars
counting ascii control sequences lead to unpredictable and early
line breaks on colorized inputs (e.g. syntax highlighted strings)
2022-10-08 19:23:38 +02:00
LingMan
a867ddb6cd
docs: Fix formatting in docs of value_parser! macro 2022-10-08 01:08:38 +02:00
Dominik Nakamura
232d91b96e
docs: Describe the skip attribute for ValueEnums (#4328)
Documenting the `skip` attribute for the `ValueEnum` derive macro promptly, as it's not mentioned anywhere else.

Fixes #4327
2022-10-05 08:22:18 -05:00
Tony Gorez
7f98947c04
feat: expose is_multiple & get_args API for ArgGroup (#4336)
Fixes #4228
2022-10-03 15:21:53 -05:00
Ed Page
dd8e242773 fix(parser): Allow defaults for Help/Version
These didn't make sense for the builder but are helpful for the derive.
The assert was assuming people wouldn't do this and to catch internal
problems.

Fixes #4326
2022-10-01 13:37:24 -05:00
Ed Page
46e238febb docs: Fix outdated short comment
Noticed as part of #4311
2022-09-30 14:49:38 -05:00
Ed Page
16e5599b71 docs: Note that author doesn't show up by default 2022-09-30 13:27:46 -05:00
Ed Page
4eb3da20f7 docs(help): Include example with old template 2022-09-30 13:21:13 -05:00
Ed Page
db31881be5 docs: Remove references to global settings
These were copied over from the original `AppSettings` and never updated
despite never being relevant in this context.
2022-09-30 13:17:46 -05:00