Commit graph

438 commits

Author SHA1 Message Date
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
Steven Tang
e5ced8bae6
docs: Changelog - error-context, help, usage flags 2022-09-22 21:11:19 +10:00
Ed Page
b0027b5943
docs: Further clarify the text 2022-09-20 16:21:10 -05:00
Tshepang Mbambo
a6822a27b4
a comma felt wrong there 2022-09-20 23:09:19 +02: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
94c5802aae docs: Update changelog 2022-09-19 09:28:56 -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
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
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
0eb95022a5 fix(help): Respect LINES and COLUMNS
Fixes #4186
2022-09-12 20:17:20 -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
75a73f3fe0 docs: Feature moved to v3 2022-09-12 16:25:18 -05:00
Ed Page
a86e55ad3e docs: Add more highlights 2022-09-09 19:06:33 -05:00
Ed Page
fadcaf9860 docs: Help people through Action changes 2022-09-08 16:02:12 -05:00
Ed Page
6f185a8704 docs: Clarify intent of upgrade link 2022-09-08 15:56:56 -05:00
Ed Page
17f49df4e2 revert(derive): Bald action/value_parser are deprecated, its good enough
When I removed these in v5, we didn't have a deprecation approach for
the derive and I didn't want to forget.  Now we do have a deprecation
approach and that is the reminder, so we don't need to carry around v5
changes.
2022-09-07 19:34:50 -05:00
Ed Page
b502ac750b docs: Summarize reason for change 2022-09-07 19:30:57 -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
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
69dd145767 docs: Fix code fence 2022-09-07 13:40:03 -05:00
Ed Page
b7b12ea558 docs: Add another highlighted difference 2022-09-07 12:45:25 -05:00
Ed Page
55e2297174 docs: Write v4 migration 2022-09-07 12:43: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
d45e4be14b fix(derive): Deprecate Command::allow_hyphen_values
Fixes #3450
2022-09-06 20:50:09 -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
47e3cb6498 docs: Update changelog 2022-09-02 15:44:41 -05:00
Ed Page
7b0c76de31 Revert "fix(derive): Remove structopt attribute support"
This reverts commit 521a012c28.
2022-09-02 11:15:15 -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
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
87cc6f9a1e docs: Add workaround to changelog 2022-08-31 09:06:43 -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
3f44dc03d2 docs: Provide workaround for title cased headings 2022-08-30 19:59:42 -05:00
Ed Page
44d3614add revert: Add some deprecated placeholders 2022-08-30 16:47:39 -05:00
Ed Page
1ca4bab206 docs: Update references in changelog 2022-08-30 16:34:20 -05:00
Ed Page
b632b4434f docs: Fix link in changelog 2022-08-30 16:32:12 -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
f3c4bfd993 docs: Forward integrate v3's changelog 2022-08-30 08:54:00 -05:00
Ed Page
5bbe04ac2a docs: Update changelog 2022-08-29 16:50:04 -05:00
Ed Page
36460aed08 fix: Deprecate _os variants
PR #4096 made them redundant
2022-08-29 12:42:30 -05:00
Ed Page
a2f3ee2cfa docs: Update changelog 2022-08-26 20:06:46 -05:00
Ed Page
521a012c28 fix(derive): Remove structopt attribute support 2022-08-26 16:06:10 -05:00
Ed Page
b4b121d3a4 fix(derive): Remove deprecated arg_enum attribute 2022-08-26 13:34:16 -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