Commit graph

263 commits

Author SHA1 Message Date
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
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
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
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
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
Ed Page
8ad29ef337 feat: Allow specifying negative nums on Arg, like hyphens 2022-09-07 07:18:19 -05:00
Ed Page
d45e4be14b fix(derive): Deprecate Command::allow_hyphen_values
Fixes #3450
2022-09-06 20:50:09 -05:00
Ed Page
7a2bbca62b fix(derive): Make Command::allow_hyphen_values forward to Arg 2022-09-06 19:41:17 -05:00
Emerson Ford
fd9a5a1d50 fix(parser): Arg::allow_hyphen_values correctly handles long args in first pos
This makes it match up with `Command::allow_hyphen_values` which was the
guiding factor for what the behavior should be.

This supersedes #4039

Fixes #3880
Fixes #1538
2022-09-06 19:41:17 -05:00
Ed Page
bffce7f57a fix: Deprecate Command::trailing_var_arg
Now that we have it on `Arg`, we don't need it on `Command`
2022-09-06 19:41:17 -05:00
Ed Page
b07d02ef46 feat: Allow specifying trailing_var_arg on Arg, like last
This has been a bit out of place being on the command.  Now its clearer
what the user intends to be the trailing var arg and it is more likely
to be discovered.
2022-09-06 19:41:14 -05:00
Ed Page
671914b590 fix(error): Make whitespace consistent with self/help
Sometimes errors would use a tab, sometimes four spaces.  This makes it
always four spaces and shares a definition with help.
2022-08-31 16:02:14 -05:00
Ed Page
439c9e7a91 feat(help): Expose clap's indentation to help_template
This will make it easier for help templates to be consistent with clap
2022-08-31 15:42:59 -05:00
Ed Page
65b5b5f7bf fix(help): Remove name/version/author from help
This is to help shorten it and polish it by removing redundant
information.

This is a part of #4132
2022-08-31 15:06:15 -05:00
Ed Page
cdb812b28b
Merge pull request #4159 from epage/help
fix(help): Clarify short vs long help
2022-08-31 14:38:12 -05:00
Ed Page
c1c269b427 fix(help): Clarify short vs long help
In reviewing CLIs for #4132, I found some were providing helps on `-h`
vs `--help` and figured that could be built directly into clap.  I had
considered not making this hint automatic but I figured the overhead of
checking if long exists wouldn't be too bad.  The code exists (no binary
size increase) and just a simple iteration is probably not too slow
compared to everything else.

Fixes #1015
2022-08-31 14:25:46 -05:00
Ed Page
9cc0299c0c test(help): Verify how version interacts 2022-08-31 14:11:00 -05:00
Ed Page
cdfd455ee6 fix(help): Always trim output
This ensures we don't end up with accidental leading or trailing
newlines due to help template variables not being used when a section is
empty.

This is prep for removing name/version from the default template and is
part of #4132
2022-08-31 09:35:33 -05:00
Ed Page
42c943844c fix(help): Use Command in place of Subcommand
In switching to title case for help headings (#4123), it caused me to
look at "subcommand" in a fresh light.  I can't quite put my finger on
it but "Subcommand" looks a bit sloppy.  I also have recently been
surveying other CLIs and they just use "command" as well.

All of them are commands anyways, just some are children of others
(subcommands) while others are not (root or top-level commands, or just
command).  Context is good enough for clarifying subcommands from root
commands.

This is part of #4132
2022-08-31 08:53:10 -05:00
Ed Page
02d27b5ce3 fix(usage): Make dont_collapse_args_in_usage the default
The setting was added to resolve #769.  The reason it was optional is out
of concern for applications with a lot of positional arguments.  I think
those cases are rare enough that we should just push people to override
the usage.  Positional arguments are generally important enough, even if
optional, to show.

As a side effect, this fixed some bugs with
`dont_collapse_args_in_usage` where it would repeat an argument in a
smart usage.

As a side effect, smart usage now shows `--` when it should
2022-08-30 16:12:49 -05:00
Ed Page
c22b78ba61 fix(usage): Don't put in [--] for multiple values
This was added in #165 but the relative value of this doesn't seem worth
the complexity at the moment.
2022-08-30 16:01:22 -05:00