Commit graph

1226 commits

Author SHA1 Message Date
Ed Page
3ac44040ef
Merge pull request #5025 from SUPERCILEX/resolve-alias-conflicts
fix: Resolve conflicting name inference if from aliases
2023-09-25 15:56:28 -05:00
Alex Saveau
a76789eb8b
fix: Make long subcommand flag inference consistent
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-09-25 13:28:27 -07:00
Alex Saveau
c2b8ec3bd3
fix: Resolve conflicting name inference if from aliases
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-09-25 13:18:54 -07:00
Alex Saveau
e5c6993cca
test: Long flags inference
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-09-25 13:18:50 -07:00
Ed Page
221177b9cb fix(assert): Call out the action in positional assert
Brought up in #5135
2023-09-25 10:18:37 -05:00
Ed Page
eb53db89f8 feat(help): Stabilize styling support
Fixes #3234
2023-08-28 09:49:48 -05:00
Ed Page
d30d94f51c chore: Update MSRV to 1.70 2023-08-24 10:14:23 -05:00
Ed Page
bf3f25ebb2 fix(help): Ensure padding isn't stripped
Fixes #5083
2023-08-22 16:02:33 -05:00
Ed Page
afefdc9414 test(help): Show padding bug 2023-08-22 16:00:10 -05:00
Ed Page
56135f3ff3 fix(builder): UnknownValueParser shouldn't error on flag absense
Fixes #5079
2023-08-18 14:29:37 -05:00
Ed Page
b55ebc9f7f test(parser): Show bad Unknown bug on flags 2023-08-18 14:19:54 -05:00
Ed Page
9f65eb0c9a refactor(error): Give caller control over suggestion 2023-08-16 14:54:45 -05:00
Ed Page
8413c155d2 feat(builder): Allow injecting known unknowns
Fixes #4706
2023-08-16 14:50:08 -05:00
Roland Fredenhagen
f16a1a76bc
chore: Clippy 2023-07-26 23:48:37 +07:00
Ed Page
8bee728034 fix(parser): Value terminator has higher precedence than later multiple values
This is one of several bugs found when looking at #4960.
2023-07-21 16:41:08 -05:00
Ed Page
bdf205bff2 test(parser): Show one value terminator bug 2023-07-21 16:05:38 -05:00
Ed Page
6590a855ee fix(parser): Don't suggest -- as often
See #2766
2023-07-21 14:27:15 -05:00
Ed Page
76b891db41 test(parser): Reproduce suggestion 2023-07-21 14:21:45 -05:00
Ed Page
8b536e2719 fix(help): Wrap long possible values correctly
We weren't taking the name into account when determining the wrap width.

Fixes #5022
2023-07-19 10:42:09 -05:00
Ed Page
4caa536ca4 fix(assert): Allow stateful value parsers
We'll need to re-evaluate how to solve #3202.

Fixes #4643
2023-07-18 14:11:56 -05:00
Ed Page
97f4c72af1 test(examples): Verify all features 2023-07-17 17:01:31 -05:00
Ed Page
0ba987fca9 refactor(test): Make it easier to compare features with manifest 2023-07-17 16:57:22 -05:00
Ed Page
36afe99bfa fix(help): Skip [OPTIONS] if help/version action
Our code for detecting when to skip this in the usage was never updated
for actions.
2023-07-17 10:40:42 -05:00
Ed Page
22b545b98b feat(help): Explicit control over short/long help
Fixes #4687
2023-07-17 10:37:26 -05:00
Ed Page
bc000aa4b0 fix(help): Defaulting max_term_width instead of max_term_width
Fixes #4295
2023-07-17 09:40:49 -05:00
Sebastian Toh
8103e9760a fix(ignore_errors): Allow help and version command 2023-06-28 08:58:40 +08:00
Sebastian Toh
d451e0a60c test(ignore_errors): Add help & version cmd tests 2023-06-28 08:55:10 +08:00
Alex Saveau
f9994bff47
fix: Broken long arg inference on conflicts
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-06-17 13:30:05 -07:00
Ed Page
d10938dd33 feat: Allow deferred initialization of subcommands
This is mostly targeted at reducing startup time for no-op commands
within *very* large applications, like deno (see #4774).

This comes at the cost of 1.1 KiB of binary size
2023-06-09 08:29:38 -05:00
Ed Page
103ae5cf62 fix(derive): Don't warn when people bring types into scope
Fixes #4951
2023-06-05 12:55:06 -05:00
Ed Page
a360fd8ac0 test(parser): Verify value terminator precedence 2023-05-19 11:04:48 -05:00
Ed Page
e1db168d69 fix(parser): Ensure terminated positionals are assigned correctly 2023-05-19 10:41:44 -05:00
Ed Page
1ee2e95e96 fix(builder): Allow value terminated multiple positional values 2023-05-19 10:39:05 -05:00
Ed Page
130b2ff997 test(parser): Show multiple positional multiple values behavior 2023-05-19 10:36:43 -05:00
Ed Page
c3fe7ff0a9 fix(help): Don't use next-line-help on long-help for subcommands
Subcommands don't switch their behavior on `--help`, so let's not switch
to next-line-help based on `--help`.

Fixes #4897
2023-05-12 10:41:05 +02:00
Ed Page
21d911db10 style: Make clippy happy 2023-05-19 09:10:20 -05:00
Ed Page
67cc5ea3a2 fix(assert): Clarify last assertion
An incremental improvement for #4911.
2023-05-17 16:33:36 -05:00
Yuri Astrakhan
d0302c5556 chore: Inline simple non-mixed format args 2023-05-04 15:58:04 -04:00
Ed Page
1351c56289 fix(help): Consistently calculate PV name length 2023-05-03 20:15:31 -05:00
Ed Page
3963d73e18 perf(help): Remove next-help possible values
Next-line help for possible values does not feel like its pulling its
weight.  If anything we should do next-line help for the entire
argument.

This dropped about 0.5 KiB but more importantly is prep for other
changes.
2023-05-03 20:09:36 -05:00
Yuri Astrakhan
797c23c415 chore: Inline format args using clippy fix
This command cleaned up all the format args,
making code significantly shorter and more readable.

```
cargo clippy --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2023-05-03 21:49:11 -04:00
Ed Page
950a495753 fix(help): Preserve block indent when wrapping 2023-04-19 11:55:53 -05:00
Ed Page
71344749e7 test(help): Show indented wrap behavior 2023-04-19 11:37:03 -05:00
Ed Page
feddd124b0 style: Move away from banned fns 2023-03-30 02:18:00 -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
Ed Page
fa60e723fc fix(error): Give more idea why we are suggesting an arg
One challenge with this is finding something that generally works.
Making this work perfectly for one setting will make it inconsistent
with other settings and take up more binary size / compile time.

So in the end, I felt like just mirroring rustc (with a bit more
brevity) seemed like a decent experiment.  This will be evaluated by the
feedback on release.

This is a small part of #4638
2023-03-27 20:45:27 -05:00
Ed Page
234d5f91d1 fix(error): Change from neutral 'note' to helpful 'tip'
This also has the advantage of aligning with `error:`

This is a small part of #4638
2023-03-27 20:45:11 -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
062622fe2d chore(derive): Update syn 2023-03-18 08:50:41 -05:00
Ed Page
e030426819 refactor(derive): Remove proc-macro-error dependency
Made things simpler that we were always aborting before.
2023-03-18 07:08:22 -05:00
Ed Page
953e2dcd34 docs: Remove remaining references to clap attribute 2023-02-18 18:42:07 -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
Martin
704d0e7a4f chore: Make format!() calls more readable 2023-01-29 19:14:47 +00: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
9d1de20787 docs: Prefer get_flag over get_one::<bool>
Inspired by #4654
2023-01-23 09:23:38 -06: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
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
084991f70a
Merge pull request #4600 from tmccombs/groups-derive
Add support for deriving grouped options for Vec<Vec<T>>
2023-01-10 08:43:36 -06:00
Ed Page
af71ada3f4 fix(derive): Allow update_from when explicit requireds used
Fixes #4617
2023-01-09 20:52:46 -06:00
Ed Page
b9ae787d6b test(derive): Show update_from bug with explicit required 2023-01-09 20:52:45 -06:00
Ed Page
7b69dea24f test(derive): Unwrap, don't exit 2023-01-09 20:52:06 -06:00
Ed Page
f25fe5b3e0 chore: Bump MSRV to 1.64.0 2023-01-09 12:29:41 -06:00
Ed Page
d745c32f4f test(builder): Fix failing test 2023-01-09 11:59:20 -06:00
Thayne McCombs
73df3d1a1e chore: Put Vec<Vec<_>> behave for derive behind unstable-v5 flag 2023-01-08 00:28:01 -07:00
Thayne McCombs
ccce3c3db5 test: Add test for opting out of Vec<Vec<T>> derive 2023-01-07 23:36:45 -07:00
Thayne McCombs
eaa9273f91 feat: Add support for deriving grouped options for Vec<Vec<T>>
Relates-To: #2924
2023-01-07 23:36:45 -07: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
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
85ecb3e895 fix(parser): Override required when parent group has conflict
Fixes #4569
2022-12-22 13:09:14 -06:00
Ed Page
d145b8b166 test(parser): Demonstrate required-overload bug 2022-12-22 13:08:02 -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
c6058dee6e fix(help_template): Added cfg 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
2a374db639 test(parser): Show bad behavior 2022-12-20 20:23:49 -06:00
Ed Page
f632424e65 test(parser): Consolidate args_conflicts_with tests 2022-12-20 20:23:44 -06:00
Ed Page
e30e9823f2 test(parser): Verify value_source 2022-11-29 20:26:37 -06:00
Ed Page
623ccbc152 style: Make clippy happy 2022-11-24 08:05:21 -06: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
d21ee513fd test(parser): Verify subcommand required message 2022-11-15 10:12:05 -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
45d26e0013 test(parser): Show UTF8 bug 2022-11-11 12:22:30 -06:00
Ed Page
ec03972023 test(assert): Verify empty positional assert exists
Wondered if we had this for #4467.  Figured we should actually test it.
2022-11-09 22:10:37 -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
c37ab6c205 fix(derive): Allow 'long_help' to force populating from doc comment
Fixes #4441
2022-11-07 09:41:52 -06:00
Ed Page
8751152316 test(derive): Verify long_help behavior 2022-11-07 09:36:53 -06:00
Ed Page
79225d3a2d fix(derive): Allow defaulted value parser for '()' fields
Inspired by #4458

This is a compatible change because it turns a compiler error into a
working case.
2022-11-07 06:07:51 -06:00
Ed Page
91daec67ca fix(derive): Allow skipping enum variants with a value
Fixes #4411
2022-10-20 16:44:51 -05: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
a4bcba6840 fix(error): Consistently indent suggestions 2022-10-13 12:10:13 -05:00
Ed Page
a964f45b1b fix(error): Properly quote, color subcommand suggestions 2022-10-13 10:51:17 -05:00