Commit graph

3185 commits

Author SHA1 Message Date
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
Ed Page
973f30fb22 refactor(docs): Use intra-doc links to avoid breakages 2022-09-30 13:16:13 -05:00
Ed Page
e53447835c docs: Fix link to crate_authors macro 2022-09-30 13:15:58 -05:00
Ed Page
1065d6c36b feat(assert): Help people know about implicit ArgGroups 2022-09-30 12:56:43 -05:00
Ed Page
c16fdbedc1 docs: Clarify term_width requires wrap_help 2022-09-30 12:30:14 -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
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
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
b814c785ef docs(derive): Correct reference 2022-09-30 08:15:48 -05:00
Ed Page
8fc8b5f273 feat: Add ArgGroup::is_required_set
This is a part of #4228

I thought I needed this for another change but it turned out I didn't.
2022-09-29 16:29:08 -05:00
Ed Page
4634812e3d refactor: Use getters internally
This originally stemmed from wrapping `Arg` in a `Box`, but we had to
smash it with a hammer as it didn't improve things enough.

- This dropped binary size by 3-7 KiB
- Parsing slowed by 20%.
- Incremental rebuilds slowed down by 1%
2022-09-29 15:26:24 -05:00
Ed Page
84055f41e4 docs: Provide more nuance on allow_hyphen_values
This matches what we hope is the right behavior, see #4283
2022-09-29 14:41:39 -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
5399f49572 fix(error): Quote literals consistently 2022-09-29 08:54:03 -05:00
Ed Page
2d86f96d64 fix(error): Stylize escape suggestions 2022-09-29 08:47:56 -05:00
Ed Page
549911a84a fix(error): Format help suggestion as literal 2022-09-29 08:43:05 -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
Wolf Thomsen
0f45ac7235
Fix inline code snippet typos
There are a couple of typos where a backtick is missing / too much which results in slightly broken formatting. This PR should hopefully fix them.
2022-09-28 21:26:56 +02:00
Ed Page
9cd1939535
Merge pull request #4269 from epage/usage
fix(error): Polish `--flag=bad-value` error
2022-09-27 09:42:11 -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
Peter Grayson
7dd216b1e6
docs: Update multiline usage override rules
The styling of usage has changed in #4188 such that the usage string is on
the same line as the "Usage:" title. Previously, the usage went on the line
below the title. As such, the rules have changed for how to make a
multiline usage format correctly.

These updated rules achieve the following output for the documented
example:

    Usage: myapp -X [-a] [-b] <file>
           myapp -Y [-c] <file1> <file2>
           myapp -Z [-d|-e]

Relates-to: #4132
2022-09-26 21:57:09 -04:00
Ed Page
a5ce7a0187
Merge pull request #4262 from epage/conflict
fix(parser): Conflict-with-self is back on by default
2022-09-26 13:41:45 -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
4a1552cc0e perf: Drop use of Into::into for '?'
For binary size, this only dropped 0.2 KiB

For performance, before:
- parse_rustup_with_sc    time:   [7.9866 µs 8.0138 µs 8.0470 µs]
After:
- parse_rustup_with_sc    time:   [7.5387 µs 7.5722 µs 7.6157 µs]

For build-time, before
```console
$ hyperfine --warmup=1 --min-runs=5 "--prepare=cargo clean" "cargo build -F cargo --example cargo-example"
Benchmark 1: cargo build -F cargo --example cargo-example
  Time (mean ± σ):     16.988 s ±  1.190 s    [User: 68.178 s, System: 6.637 s]
  Range (min … max):   15.550 s … 18.277 s    5 runs
```
After:
```console
$ hyperfine --warmup=1 --min-runs=5 "--prepare=cargo clean" "cargo build -F cargo --example cargo-example"
Benchmark 1: cargo build -F cargo --example cargo-example
  Time (mean ± σ):     15.674 s ±  0.222 s    [User: 62.287 s, System: 4.608 s]
  Range (min … max):   15.426 s … 15.993 s    5 runs
```
2022-09-26 12:31:39 -05:00
Ed Page
c4b3a4f491 refactor: Remove use of '?' 2022-09-26 12:19:30 -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
bac3eb3280 docs: Raise visibility of 'string' feature 2022-09-26 11:14:06 -05:00
Ed Page
bd6b67c605 style: Make clippy happy 2022-09-26 09:55:02 -05:00
Ed Page
31f9234cc7 feat(parser): Add From<str> and From<String> 2022-09-26 09:51:44 -05:00
Ed Page
931b6338f1 refactor(parser): Clarify FromStr from future FromStr 2022-09-26 09:51:03 -05:00
Ed Page
76ec238b45 docs: Clarify value_parser implementation 2022-09-26 09:50:51 -05:00
Ed Page
9f49c0c630 feat(parser): Support From<OsString> for value_parser 2022-09-26 09:50:49 -05:00
Ed Page
e64ed91a4e feat(parser): Support From<&OsStr> types for value_parser!
Last time I tried this, I wasn't able to resolve the lifetime issues.  I
seemed to have gotten it working this time.

This came up in #4254.
2022-09-26 09:50:12 -05:00
Ed Page
037b07577c feat: Expose ANSI styling to the user
This gives users the control over where clap outputs while still getting
colors.  For users who want to support old windows versions, check out
`fwdansi` crate.
2022-09-22 09:59:42 -05:00
Ed Page
a2272a2c50 feat(error): Add a 'render' method 2022-09-22 09:55:11 -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
a76f622d17 docs: Clarify when quoting is required for arg 2022-09-21 11:49:18 -05:00
Ed Page
2bbb81f311 docs: Clarify value parser
Things that tripped up a user
- Derive reference was misunderstood to say that the only alternative to
  the built-in value parser behavior was to implement
  `ValueParserFactory`
  - We now delegate to `value_parser!`s docs any talk of integrating
    into it (it should have been a subbullet of "not present" anyways)
- `value_parser!` relies too much on the example to demonstrate behavior
  when the user will likely make the determination of whether its
  relevant before then
  - We are now more upfront what type mappings are supported
- Too many steps to find all information
  - For example, a user needs to look at `TypedValueParser`
    implementations, `ValueParserFactory` implementations, and `From<T>
    for ValueParser` implementations to understand what all can be used
  - We are now more upfront with a lot of this information at the entry
    points the user is most likely to look at

In addition, I did an audit of the docs to make sure they were updated
for us only supporting the new behavior and all of the new APIs.

See https://www.reddit.com/r/rust/comments/xjlie4/preannouncing_clap_40_a_rust_cli_argument_parser/ip9kzf1/
2022-09-21 11:11:21 -05:00
Ed Page
99dfe7404a docs(ref): Remove dead example
This was missed in the migration to the reference being on docs.rs.  Not
feeling its worth finding a way to integrate it into the new structure.
2022-09-21 11:02:08 -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
745fa9927a perf(help): Remove more from usage feature
Quality of error-context goes down with this.
2022-09-19 14:03:55 -05:00
Ed Page
bfa365a2cc feat(help): 'usage' feature flag for auto-genned usage 2022-09-19 13:15:47 -05:00
Ed Page
80f616a4b3 refactor(parser): Clarify argument 2022-09-19 13:02:26 -05:00
Ed Page
553a93efc8 refactor(help): Make usage optional 2022-09-19 12:15:52 -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
6ea5d46300 refactor(help): Move near use 2022-09-19 11:26:06 -05:00
Ed Page
9036d3fd3c refactor(help): Split out help templates 2022-09-19 11:20:18 -05:00
Ed Page
e75da2f868 perf(help): Reduce colorless code size
This takes off another 14 KiB when color us not used.  My hope is that
we'll be able to switch away from `termcolor` to a term styling crate
that will make this work in the color case as well.
2022-09-19 10:36:43 -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
ba9e6d052a feat(error): Provide abstraction for default formatter 2022-09-19 09:38:16 -05:00
Ed Page
e9f1287b63 fix(help): Separate command flags like options
Fixes #4232
2022-09-19 09:07:43 -05:00
Ed Page
ad05d1624b fix(help: Be more precise on literal vs not 2022-09-19 09:05:44 -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
fe43f0c945 Revert "fix: Remove once_cell dependency from derive"
This reverts commit 429143af42.
2022-09-16 16:19:03 -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
10854cd262 Revert "refactor: Remove once_cell dependency"
This reverts commit c9d883a8c6.
2022-09-16 16:14:32 -05:00
Ed Page
7ccaebb65d refactor(parser): Switch from Box<str> to String
This is a more familiar type for people and it didn't cost us anything
(in fact it undid the code size change in the last commit).
2022-09-16 16:14:32 -05:00
Ed Page
1e13109a26 refactor(parser): Track subcommands with Box<str>
The overall hope is to allow a `&'static str`-only version of clap, so
we need to move off of `Str` where dynamic strings are required.  We
need it here for subcommands due to external subcommands.

This had minimal impact on code size (567.2 to 567.5 KiB)
2022-09-16 16:14:32 -05:00
Ed Page
86b2fe5a2d refactor(parser): Reduce work when validating args 2022-09-16 16:14:16 -05:00
Ed Page
af9e1b9763 refactor(parser): Don't throwaway work 2022-09-16 16:14:16 -05:00
Ed Page
4869c43612 refactor: Simplify help subtree creation 2022-09-16 16:14:16 -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
dbf2c86995 perf: Misc simplifications for code size
This dropped a fraction of a KiB but it will at least not cause people
to ask if it'd help to simplify in the future.
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
23ce67e323 feat: Allow resetting builder methods
Fixes #4178
2022-09-13 15:16:57 -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
da9691d369 docs: Clarify role of max_term_width 2022-09-13 11:40:06 -05:00
Ed Page
01c0975678 feat(derive): Reserve 'group_id' trait method 2022-09-13 07:06:12 -05:00
Ed Page
0eb95022a5 fix(help): Respect LINES and COLUMNS
Fixes #4186
2022-09-12 20:17:20 -05:00
Ed Page
0760498200 refactor(help): Allow looking up dimensions independently 2022-09-12 19:55:13 -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
430a384984
Merge pull request #4196 from epage/link
docs(parser): Clarify needs for negative numbers
2022-09-07 20:00:49 -05:00
Ed Page
fa7a1fca58 docs(parser): Clarify needs for negative numbers 2022-09-07 19:48:10 -05:00
Ed Page
afeed4043c perf(assert): Don't make release pay the cost 2022-09-07 19:43:26 -05:00
Ed Page
985a1b9b4a docs(derive): Collect tips at end 2022-09-07 18:56:05 -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
ed6475e9de fix(help): Clarify what is tab dependent and what isn't 2022-09-07 16:39:14 -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
876da97d1c fix(help): Make next-line help less sensitive to tab changes 2022-09-07 15:52:26 -05:00
Ed Page
d3fc37b678 fix(help): Long-only indentation is independent of TAB 2022-09-07 15:07:47 -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
61f8a9375a docs: Show how last can be used
We can't quite get git's behavior because it has `last` as both before
and after `--`
2022-09-07 11:27:39 -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
16d5a2a19a perf: Shrink the code 2022-09-07 07:00:58 -05:00
Ed Page
2ebe5ae795 docs: Cross-link allow_hyphe_values with trailing_var_arg 2022-09-06 21:24:06 -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
94a5e7fa1a refactor(parser): Highlight short/long parallels 2022-09-06 19:41:17 -05:00
Ed Page
bc5c5e4a9f fix(parser): Make Command/Arg behave same for shorts with allow_hyphen_values 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
9a4c2bc990 docs: Improve description around trailing_var_arg 2022-09-06 14:34:47 -05:00
Ed Page
1dd9245fff refactor: Use parameters over settings 2022-09-06 14:43:02 -05:00
Ed Page
0e915e0d3a docs(derive): Update for new attributes 2022-09-02 15:39:13 -05:00
Ed Page
5112372c77 feat(parser): Provide convenience for SetTrue
I wanted to make `bool` a defaulted type parameter but
https://github.com/rust-lang/rust/issues/36887
2022-09-01 19:40:56 -05:00
Ed Page
80ec011b6e feat(parser): Provide convenience accessor for Counts 2022-09-01 19:19:55 -05:00
Ed Page
cdcbf1300d fix(usage): Have spillover use TAB
This was missed in #4161
2022-08-31 16:20:56 -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
803d87b193 refactor(help): Reduce magic numbers 2022-08-31 15:39:15 -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
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
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
c4dd6aeb42 docs: Update example help 2022-08-30 19:57:26 -05:00
Ed Page
44d3614add revert: Add some deprecated placeholders 2022-08-30 16:47:39 -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
Ed Page
a00cbab1dc fix(usage): Don't list -- as optional for last
`last` must always follow a `--`, so it isn't optional.
2022-08-30 15:41:35 -05:00
Ed Page
d791a93ec7 refacor(usage): Remove use of sort 2022-08-30 11:27:14 -05:00
Ed Page
1dde9268d5 fix(usage): Don't include irrelevant parent args
This was identified in https://github.com/clap-rs/clap/discussions/4134
2022-08-30 13:43:31 -05:00
Ed Page
8da1f085dd fix(parser): Require earlier, not-present positionals 2022-08-30 09:31:46 -05:00
Ed Page
2388ace47b refactor(parser): Hoist check into iteration 2022-08-30 08:47:03 -05:00
Ed Page
619b1fb187 perF(usage): Defer de-duplicating to later
This should drop code size
2022-08-30 07:15:50 -05:00
Ed Page
66957f8398 refactor(usage): Make last check clearer 2022-08-29 21:26:39 -05:00
Ed Page
09031fb4ab refactor(usage): Consolidate required bookkeeping 2022-08-29 21:26:35 -05:00
Ed Page
85569514db refactor(usage): Make duplicate check more resilient 2022-08-29 21:26:32 -05:00
Ed Page
3b17f7fdc9 refactor(usage): Pull out duplicate check 2022-08-29 21:26:28 -05:00
Ed Page
ecb632f487 refactor(usage): Split out group processing 2022-08-29 21:26:24 -05:00
Ed Page
26ea3e32d0 refactor(parser): Consolidate the loops 2022-08-29 19:42:21 -05:00
Ed Page
0c9b9d7ec8 fix(parser): Show all required errors at once
This also has the side effect of always using the "smart usage" which is
why the tests changed.
2022-08-29 19:40:35 -05:00
Ed Page
14d910dee1 refactor(parser): Prefer explicit for loops 2022-08-29 17:04:17 -05:00
Ed Page
3c466c63f7 refactor(parser): Flatten required_unless logic 2022-08-29 17:02:05 -05:00
Ed Page
dacc8ff43a refactor(parser): Consolidate presence check 2022-08-29 16:59:58 -05:00
Ed Page
76dd3a18e2 fix(help): Ensure consistency in usage 2022-08-29 15:50:39 -05:00
Ed Page
02db3043e2 fix(help): Consistently use [] for positionals
In the usaeg we use `[]` but in the arg list we use `<>`.
2022-08-29 15:34:30 -05:00
Ed Page
5ef803f01a refactor(help): Move close to use 2022-08-29 15:18:46 -05:00
Ed Page
91332267cf refactor(help): Positive logic can clarify intent 2022-08-29 14:29:32 -05:00
Ed Page
87e2d0c2e0 refactor(help): Clarify intent of fn 2022-08-29 14:07:10 -05:00
Ed Page
2b4541fab2 refactor(help): Clean up code 2022-08-29 14:04:27 -05:00
Ed Page
36460aed08 fix: Deprecate _os variants
PR #4096 made them redundant
2022-08-29 12:42:30 -05:00
Ed Page
4eeee9b110 fix(help): Command::print_help should respect disable_colored_help 2022-08-29 10:47:08 -05:00
Andrew Shu
eec047a6f6 fix(help): Do not propagate global args to help
This prevents global args from showing in help completions,
since help completions should only suggest subcommands.
Adds tests to ensure the args still show in the generated
help messages of subcommands.
2022-08-26 17:48:58 -07:00
Ed Page
294868f5d8
Merge pull request #4115 from talklittle/completion-help-parser-flag
feat(complete): Add completion for help subcommands
2022-08-26 15:28:21 -05:00
Andrew Shu
0d0be51606 fix(complete): Fix help completion issues
* Copy hide flag

* Revert global args special handling. Another commit will
address the issue of whether global args should be included in
help subtrees.
2022-08-26 12:57:12 -07:00
Ed Page
e02648e66b fix(help): Don't dim placeholders
This came from feedback: https://rust-lang.zulipchat.com/#narrow/stream/220302-wg-cli/topic/Help.20changes.20in.20clap.20v4
2022-08-26 11:46:44 -05:00
Ed Page
83d6add9aa fix(help): Shift focus to subcommands, when present
In surveying various tools and CLI parsers, I noticed they list the
subcommands first.  This puts an emphasis on them which makes sense
because that is most likely what an end user is supposed to pass in
next.

Listing them last aligns with the usage order but it probably doesn't
outweigh the value of getting a user moving forward.
2022-08-26 10:59:40 -05:00
Ed Page
9b23a09f7a fix(help): Don't rely on ALL CAPS for headers
I see them fulfilling two roles
- A form of bolding
- As a callback to their placeholder in usage

However, it is a bit of an unpolished look and no other CLI seems to do
it.  This looks a bit more proefessional.  We have colored help for
formatting and I think the sections relation to usage will be clear
enough.
2022-08-26 10:21:18 -05:00
Ed Page
8315ba3dd6 fix(error): Don't underline indentation 2022-08-26 07:15:57 -05:00
Ed Page
6079a871a0 fix(help): Use a more neutral palette
Fixes #2963
2022-08-25 19:23:52 -05:00
Andrew Shu
729406661c refactor(complete): Clean up help completion
* Manual subtree copy to ensure correct behavior and settings
* Always set ExpandHelpSubcommandTrees in Command::build
* Remove redundant logic
2022-08-25 15:43:27 -07:00