Commit graph

2131 commits

Author SHA1 Message Date
Ed Page
ef823bbeaf chore: Release 2022-01-05 16:28:24 -06:00
Ed Page
faf3861bf1 fix(parser): Loosen asserts for now
This is a surgical workaround for #3263.  It makes `cargo` pass tests!
2022-01-05 16:07:39 -06:00
Ed Page
e9f6ef6638 fix(parser): Fix more panic quotes 2022-01-04 16:10:26 -06:00
Ed Page
2b2e2c9a80 fix(parser): Fix quoting in panic
We ended up with an extra quotation mark that was left unmatched.  Got a
bit confused when I saw this.
2022-01-04 15:52:14 -06:00
Dominik Boehi
ae55a9da68
Correct replacement function for Parser::from_clap 2022-01-04 22:29:39 +01:00
Ed Page
4ea1965789 chore: Release 2022-01-04 13:07:10 -06:00
Ed Page
7e4cd43620 feat(parser): Allow users to avoid undefined arg asserts
Cargo is an example of a user that heavily relied on using undefined
names because there is a lot of code sharing between commands.  This
allows a path forward for those users that is just painful enough to
discourage overly relying on it in the future :).
2022-01-04 12:53:03 -06:00
Ed Page
9daefba196 chore: Release 2022-01-04 11:42:50 -06:00
Ed Page
91de3eb0cd fix: Clarify cause of debug asserts
Ran into one of these being a pain with porting cargo.
2022-01-04 11:30:33 -06:00
Ed Page
d9906eb150 chore: Release 2022-01-04 09:49:41 -06:00
Ed Page
fa5daf4039
Merge pull request #3250 from epage/hyphen
fix(parser): Ignore Last when checking Hyphen Values
2022-01-04 09:46:59 -06:00
Daniel Eades
e8516a9098 style: allow unused field 2022-01-04 09:20:34 -06:00
Daniel Eades
35d7841211 style: simplify boolean expressions 2022-01-04 09:20:30 -06:00
Daniel Eades
e1b21784a0 fix: add 'must_use' attributes to methods returning 'Self' 2022-01-04 09:20:24 -06:00
Daniel Eades
021b1f6997 style: remove useless conversions 2022-01-04 09:20:21 -06:00
Daniel Eades
7f71d642cd style: prefer 'char' to 'str' for single character patterns 2022-01-04 09:20:08 -06:00
Ed Page
15704dcaff fix(parser): Ignore Last when checking Hyphe Values
This was found with #3249
2022-01-04 09:16:03 -06:00
Ed Page
e6ee585a4b fix: Clarify short rejection in debug 2022-01-04 09:00:13 -06:00
Ed Page
d392b88bd5 chore: Release 2022-01-03 12:12:28 -06:00
Ed Page
e5806830f3 fix: Don't panic when getting number of values
I was tempted to remove the exact-size nature.  Wouldn't be breaking
since it only panics but decided to go ahead and do this for now.

Fixes #3241
2022-01-03 11:53:59 -06:00
Ed Page
c01ebbac17 chore: Release 2021-12-31 14:35:02 -06:00
Ed Page
bc951e4e53 chore: Release 2021-12-31 13:37:28 -06:00
Ed Page
8d73a0e80f chore: Release 2021-12-31 12:23:47 -06:00
Ed Page
88a335ff97 fix(complete): Give crates more specific names
`clap_generate` originally intended to be "generate anything".  With
`fig`, we already broke one part out.  With #3174's man support, we are
also looking at keeping it separate:
- More freedom to iterate on the API
- Uniqueness (and potential weight) of its dependencies
- man generation is normally more for distribution while completions are
  a mix of being distributed with the app or the app generating the
  completions (which will be exacerbated if we move most completion
  parsing logic to be in Rust)

So `clap_generate` is having a lot more limited of a role than the
original name conveys.   I worry the generic name will be a hindrance to
people discovering and using it (yes, documentation can help but there
are limits).

I hesitated because we are on the verge of releasing 3.0. However, doing
it even later will be even more disruptive because more people will be
using it (crates.io lists ~70 people using `clap_generate`).

To ease things, we are still releasing `clap_generate` as a wrapper
around `clap_complete`.
2021-12-31 12:03:29 -06:00
Ed Page
2d7dc1ff8f chore: Release 2021-12-30 15:00:19 -06:00
Ed Page
29d4508e2a docs(derive): Link to ref from traits
This is to help with #3189
2021-12-30 14:41:26 -06:00
Ed Page
889a70ebac fix(help): Prefer short version over long version
When we got #3193, we decided in #3196 that `--help` will give a summary
for other commands (`subcmd --help` in this case) but not show the long
version of the output for that other command.

Now with #3215, I think the case is similar for `--help` not showing the
long version but instead preferring the short version and encouraging
people to run `--version`.

Originally. clap only showed the short version or nothing.  This was
changed in #2369 without fanfare to prefer the long version over short.
Now are we preferring short version over the long version always, just
like all other help.

Fixes #3215
2021-12-30 12:21:19 -06:00
Ed Page
e5fbdc9b95 Revert "Remove {n} support"
This reverts commit 333b993481.

PR #1810's motivation was effectively "this is redundant with `\n`".
That is a fine motivation.  Unfortunately, we don't have a way to force
a hard break in `clap_derive`.  #2389 should help with this eventually
but we shouldn't hold up 3.0 to get that ready.  So in the mean time, we
are restoring `{n}`.

We have #3230 for tracking the re-removal of it.
2021-12-30 11:44:45 -06:00
Ed Page
771a44bcef fix: Remove overriden occurrences as we go
This allows two overriding args to interact with each other mid-line.
This was broken in 7673dfc / #1154.  Before that, we duplicated the override
logic in several places.

Now we plug into the start of a new arg which allows us to do this
incrementally without making the logic complex or inefficient, thanks to
prior refactors.

Fixes #3217
2021-12-27 15:32:37 -06:00
Ed Page
c54ea7f4c4 refactor: Propagate AllArgsOverrideSelf during build
This will have a slight performance hit as `AllArgsOverrideSelf` will
allocate a single-element `Vec` per `Arg`.  This can be lessened for
positional and multiple occurrences by shifting those checks up into the
propagation check.

Long term, I'd like to see all of the `Arg`-in-`App` settings switch to
this which will make it easier for callers, like completions and man
pages, to figure out whats going on without duplicating the logic.

Short term, this is motivated by wanting to change the override logic to
accomodated interleaved overrides from #3217.  Moving this logic will
make it easier to change the override logic.
2021-12-27 15:04:07 -06:00
Ed Page
cb393e4439 refactor: Always inc occurrences before adding values
This is the logical order people think in terms of (`--foo` comes before
`val` in `--foo val`). This also opens things up for using occurrence
incrementing as a place to handle occurrence transitions, like
overrides.
2021-12-27 15:03:02 -06:00
Ed Page
d7f27e8732 refactor: Harden against occur/val ordering
This makes some naming more explicit and allows us to increment
occurrences before adding values (which is the logical mental order and
allows other improvements).
2021-12-27 14:50:50 -06:00
Ed Page
2d1dfae318 refactor: Clarify MatchArg::all_val_groups_empty 2021-12-27 14:21:04 -06:00
Ed Page
3db09f4dd4 fix: Don't panic on lack of conflicts
Fixes #3197
2021-12-23 13:38:23 -06:00
Ed Page
02f4ff2115 refactor: Allow more conflicts to be reported 2021-12-23 11:18:22 -06:00
Ed Page
f24b9f50de refactor: Make it easier to get groups 2021-12-23 11:15:11 -06:00
Ed Page
ad127fcc53
Merge pull request #3205 from epage/unless
fix: Ensure we validate required-unless
2021-12-23 08:47:23 -06:00
Ed Page
895e85714b chore: Remove the TODO chaff
The intent is to make stand out more the important technical debt hidden
in comments.
2021-12-22 10:15:09 -06:00
Ed Page
88c927aad3 refactor: Clarify validator relationships
We were storing data off into the struct, obscuring the direct
relationship between gathering and validating conflicts.

With this, not as much code needs to deal with mutable data
2021-12-22 09:14:39 -06:00
Ed Page
2e73be43f1 fix: Ensure we validate required-unless
Found this when digging into #3197
2021-12-21 20:41:17 -06:00
Ed Page
2d462cd0b5 fix(debug): Refer to correct function 2021-12-21 20:35:23 -06:00
Ed Page
318b7859dc fix(help): Don't infer long help from subcommands
Fixes #3193
2021-12-17 09:25:00 -06:00
Ed Page
b4fbd05196 docs(derive): Call out need for derive feature
And other derive tweaks.  I'm mixed on how far to go, including
- Linking to the derive reference
- Showing how to use each trait with both the derive and builder APIs

For now, this is an improvement.
2021-12-16 12:05:52 -06:00
Ed Page
d14255dc00 docs: Show features in docs.rs
Confirmed this works with [`argfile`](https://docs.rs/argfile/latest/argfile/)

And then running in clap
```
$ RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features
```
They now show up!
2021-12-16 10:38:31 -06:00
Ed Page
dee3adbd34 fix: Loosen lifetimes on PossibleValue 2021-12-16 09:07:05 -06:00
Ed Page
9e64387ef0 revert(help): Partial revert of 3c049b4
The extra whitespace was targeted at machine processing for a subset of
users for a subset of runs of CLIs.  On the other hand, there is a lot
of concern over the extra verbose output.

A user can set the help template for man, if desired.  They can even do
something (env? feature flag?) to make it only run when doing man
generation.  We also have #3174 in the works.

So let's focus on the end-user reading `--help`.  People wanting to use
`help2man` have workarounds to do what they need.

Fixes #3096
2021-12-15 10:36:59 -06:00
Ed Page
80f426af49 feat!: Allow resetting abouts/help to default
I dislike the inconsistency with only a few fields providing this (this
and `help_heading`) but this is to address a specific bug.  We need to
visit this, along with iterators (#2870) and string handling (#2150).

`Arg` came along for the ride because the derive logic is applied to
both.  `PossibleValue` didn't need it because we filter out `long_help`.

BREAKING CHANGE: We changed the signatures for `App::about`,
`App::long_about`, `Arg::help`, and `Arg::long_help` from accepting
anything `Into<&str>` to `&str`.
2021-12-14 11:07:39 -06:00
Ed Page
19ed78c64f fix(help): Don't commit to '--help' that doesn't work
We have two ways of fixing this
- Making `--help` work
- Don't put `--help` in the help output

For now, I went with the latter.  I tried to make it clear what the
actual requirement is so we can pivot if needed.

Fixes #2892

This happens to also fix the interaction of `DisableHelpFlag` with the
help subcommand and complcations.  I've added a test to help catch if we
break this by changing how we fixed the original issue.

Fixes #2724

These issues were reported against clap3.  I've not tried to reproduce
these in clap2 to see if they should show up in the release notes.
2021-12-13 15:59:14 -06:00
Ed Page
fa439d4f27
Merge pull request #3168 from epage/error
Ensure trailing newlines at the end of errors
2021-12-13 14:15:22 -06:00
Ed Page
a72e5726f8 fix(error): Ensure newline on value_of_t not found
Found this when auditing for cases related to #2787.
2021-12-13 13:30:32 -06:00