Commit graph

1072 commits

Author SHA1 Message Date
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
f86cd0f2ec
Merge pull request #4350 from epage/option
feat(derive): Support `Option` when flattening
2022-10-05 16:48:27 -05:00
Ed Page
06d2049931 feat(derive): Support 'Option' when flattening 2022-10-05 16:21:00 -05:00
mattmadeofpasta
b03b60edd1
test(derive): Clarify doc comment 2022-10-04 16:25:07 -04:00
mattmadeofpasta
476a8af4e2
test(derive): Rename text case 2022-10-04 16:24:47 -04:00
Ed Page
7ceb08ac70 fix(derive): Apply doc comments for #[command(subcommand)]
This was broken in 8a5a9ba931.  I had
missed this case for parsing doc comments.
2022-10-03 16:04:38 -05:00
Ed Page
39b1ef076e test(derive): Show derive bug 2022-10-03 15:40:59 -05:00
Ed Page
5f145a23e9 fix(derive): Support 'group' attribute with Parser 2022-09-30 13:44:10 -05:00
Ed Page
1065d6c36b feat(assert): Help people know about implicit ArgGroups 2022-09-30 12:56:43 -05:00
Ed Page
42122787d7 feat(derive): Report the group id
This will be needed when we support flattening for #3165
2022-09-30 12:24:21 -05:00
Ed Page
50ad905b6a feat(derive): Implicitly populate groups from some structs
This implements the basics for #3165, just missing
- `flatten` support (waiting on improved group support)
- `group` attributes
2022-09-30 11:42:06 -05:00
Ed Page
5017f0d720 fxi(error): Don't report unrelated groups in requries errors 2022-09-30 11:18:47 -05:00
Ed Page
e1b02a11cc test: Demonstrate bad requires error 2022-09-30 11:02:44 -05:00
Ed Page
cb04c71105 fix(error): Don't report unrelated groups in conflict errors
Ideally, a conflict caused by a group itself would show the relevant
group but that is less important than showing a valid, non-garbage,
usage
2022-09-30 10:38:27 -05:00
Ed Page
76b7579341 test: Demonstrate bad group error 2022-09-30 10:00:24 -05:00
Ed Page
993b0a88d7 test: Expand group test 2022-09-30 09:53:09 -05:00
Ed Page
2498147138 feat(derive): Allow skipping the implicit ArgGroup
This was prioritized to allow users to workaround problems when the
implicit `ArgGroup` is getting in the way.

Fixes #4279
2022-09-30 09:15:38 -05:00
Ed Page
35eeba0b63 test(derive): Show failure in #4279 2022-09-30 09:05:48 -05:00
Ed Page
4e9f3cca2c fix(error): Specialize the self-conflicts error
Inspired by rust-lang/cargo#11159
2022-09-29 09:54:20 -05:00
Ed Page
2c097814e4 test(error): Self-conflict 2022-09-29 09:43:33 -05:00
Ed Page
5399f49572 fix(error): Quote literals consistently 2022-09-29 08:54:03 -05:00
Ed Page
3683e2c791 fix(parser): Allow one-off self-overrides
bat needed this.

See also #4261
2022-09-28 16:45:35 -05:00
Ed Page
2d7874948f fix(parser): SetFalse should also not allow self-override 2022-09-28 16:26:36 -05:00
Ed Page
cb1cd67009 fix(error): Include failed arg in usage in --flag=bad-value error 2022-09-27 09:25:24 -05:00
Ed Page
12d76d649a fix(error): Include 'Usage:' title in --flag=bad-value error 2022-09-27 09:20:42 -05:00
Ed Page
3a8d2a579b test(parser): Verify existing --flag=bad-value case 2022-09-27 09:19:27 -05:00
Ed Page
9bccded7ed fix(parser): Conflict-with-self is back on by default
See #4261 for more details
2022-09-26 13:29:48 -05:00
Ed Page
3c9bca5ead fix(help)!: Wrapping is behind wrap_help
If users don't want `wrap_help` feature, they can put newlines in where
needed.  Seems odd to support wrapping when the wrap size is fixed.  For
those hard coding the lines, this will save them a decent amount of
size.
2022-09-26 11:45:44 -05:00
Ed Page
4280fdfcbd fix(help): Replace help writers with renderers
The writer is less convenient and isn't offering any performance
benefits of avoidign the extra allocations, so let's render instead.

This supersedes #3874

Fixes #3873
2022-09-22 09:54:19 -05:00
Ed Page
652e71d616 fix(help)!: Provide styled usage to user
This will open us up to providing the user with access to the styled
version in the future.
2022-09-22 09:54:19 -05:00
Ed Page
4674e43493 fix(error): Remove RawFormatter
The likelihood of using this is a lot lower now with `KindFormatter` and
`error-context` feature flag.

People can implement it themselves.
2022-09-20 13:40:18 -05:00
Ed Page
90bcb7f75e fix(error): Use a non-generic Error alias
`clap::Error::raw` was producing ambiguity errors with a default generic
parameter on `clap::error::Error` (which `clap::Error` is a re-export
of).

I tried making `clap::Error` a type alias with a default generic
parameter but that ran into an ambiguity error with `map_err`.

So I'm going ahead and hard coding `clap::Error`.  We don't expect
people to change this all that often.
2022-09-20 13:37:02 -05:00
Ed Page
bfa365a2cc feat(help): 'usage' feature flag for auto-genned usage 2022-09-19 13:15:47 -05:00
Ed Page
7a5dad89ff feat(help): Break out help feature flag
This removes auto-generated help, saving about 50 KiB.
2022-09-19 11:54:10 -05:00
Ed Page
2d83a7b12e feat(error): Break out error-context feature flag
This is a cheap pass at creating this to allow cutting out the cost of
rich error information / programmatic error information.

This cuts about 20 KiB off of the binary.

There is more we could cut out, like collecting of used arguments for
the usage, but I want to keep the conditionals simple.
2022-09-19 10:23:55 -05:00
Ed Page
b4788d51f1 fix(error): Provide a no-context alternative to RichFormatter 2022-09-19 09:48:54 -05:00
Ed Page
c165b601ac perf: Switch to &'static str by default
Originally, clap carried a lifetime parameter.  When moving away from
that, we took the approach that dynamically generated strings are always
supported and `&'static str` was just an optimization.

The problem is the code size increase from this is dramatic.  So we're
taking the opposite approach and making dynamic formatting opt-in under
the `string` feature flag.  When deciding on an implementation, I
favored the faster one rather than the one with smaller code size since
small code size can be gotten through other means.

Before: 567.2 KiB, 15.975 µs
After: 541.1 KiB, 9.7855 µs
With `string`: 576.6 KiB, 13.016 µs
2022-09-16 16:44:39 -05:00
Ed Page
bbbaca2ffe perf: Hint to the compiler when once_cell isn't needed 2022-09-16 16:14:32 -05:00
Ed Page
acb0fb7809 fix: Generalize mut_arg, like mut_subcommand
This makes us accept `str` and not do any allocations at the cost of
panicing if unsupported which I think fits our overall story in trying
to catch development-time errors.
2022-09-16 15:31:49 -05:00
Ed Page
14c6ce0e83 fix(derive): Remove next_help_heading isolation
Originally, I saw the ideal as the parent command being isolated from
`#[clap(flatte)]` especially after all of the doc comment
leakage issues.  We scaled that back to just `next_help_heading` because
of the issues with settling on a policy and maintenance to cover
everything.  When doing `next_display_order`, we decided it would mess
things up too much to isolate it.

With #1807, we instead have been moving towards setting
`#[command(next_help_heading)]` anywhere, we just need to finish working
out how it should work.
2022-09-16 15:31:49 -05:00
Ed Page
0184cf008a fix(parser): Quote the suggested help
We do it elsewhere but here it is only distinguished coloring.

Inspired by #4218
2022-09-15 16:24:59 -05:00
Ed Page
b7d13dfb88 fix(parser): Prefer invalid subcommands over invalid args
Just having `--help` or `--version` can make us get invalid args instead
of invalid subcommands.   It doesn't make sense to do this unless
positionals are used.  Even then it might not make sense but this is at
least a step in the right direction.

Unsure how I feel about this being backported to clap 3.  It most likely
would be fine?

This was noticed while looking into #4218
2022-09-15 10:30:03 -05:00
Ed Page
f68500d9fd fix: Replace Arg::env with Arg::env_os
With `Into<OsStr>`, the separate function isn't needed.
2022-09-13 14:55:12 -05:00
Ed Page
d3bf5450ff feat(derive): Reserve the T group name
Since the `name` is changed to be the package name, we can't use it as
(1) its not as predictable and (2) it can lead to conflicts if a
`Parser` is flattened into a `Parser`
2022-09-13 07:44:36 -05:00
Ed Page
c9eef44213 fix: Make arg!(--flag <value>) optional by default
This was ported over from the usage parser which modeled after docopt.
We just never got around to implementing the rest of the syntax.

However, when considering this as a standalone feature, an
`arg!(--flag <value>)`, outside of other context, should be optional.
This is how the help would display it.

Fixes #4206
2022-09-12 17:10:01 -05:00
Ed Page
c90a4eabae fix(help): Make output more dense
In looking at other help output, I noticed that they use two spaces, in
place of clap's 4, and it doesn't suffer from legibility.  If it
doesn't make the output worse, let's go ahead and make it as dense so we
fit more content on the screen.

This is a part of #4132
2022-09-07 17:13:55 -05:00
Ed Page
56fe50eab8 fix(help): I think this fixes a bug?
The existing behavior is hard to explain, so this is the best I've
figured is going on.
2022-09-07 16:38:33 -05:00
Ed Page
bbb6c38bad fix(help):Be dense on short next line help
If short help is too long for the terminal, clap will automatically
switch to next line help.  As part of next line help for longs, we add a
blank line between args.  This helps make the args clearer when dealing
with multiple paragraphs.  However, its not as much needed for short and
subcommands (always short), so now short matches subcommands.

This was inspired by #3300 and a part of #4132
2022-09-07 14:05:17 -05:00
Ed Page
9a645d2d19 fix(help): Collapse usage to one line
After looking at more examples, I've become more attached to this
briefer format.

Part of #4132
2022-09-07 11:03:57 -05:00
Ed Page
1258f3e5f6 fix: Deprecate Command::allow_negative_numbers
Better to set on individual args
2022-09-07 07:24:42 -05:00