Commit graph

2384 commits

Author SHA1 Message Date
Ed Page
2b60c598b7 feat(error: Expose too-many context 2022-02-04 13:53:57 -06:00
Ed Page
03fbb50283 refactor(error): Make room for more values 2022-02-04 13:44:49 -06:00
Ed Page
f7731d1f03 feat(error: Expose invalid-utf8 context 2022-02-04 13:42:36 -06:00
Ed Page
f54bcc85b7 feat(error: Expose missing-subcommand context 2022-02-04 13:18:51 -06:00
Ed Page
9b18f8087c feat(error: Expose missing-required context 2022-02-04 12:45:48 -06:00
Ed Page
71535866b9 feat(error: Expose invalid-subcommand context 2022-02-04 12:23:06 -06:00
Ed Page
5095e5c992 feat(error: Expose unrecognized-subcommand context 2022-02-04 11:15:22 -06:00
Ed Page
1a0d7bac29 feat(error: Expose invalid-value context 2022-02-04 10:24:51 -06:00
Ed Page
04aa6029b8 refactor(error): Generalize kind name 2022-02-04 10:08:51 -06:00
Ed Page
1463f82cf1 feat(error: Expose no equals context 2022-02-04 10:07:14 -06:00
Ed Page
9759f2f1ea refactor(error): Share template across kinds 2022-02-04 10:03:09 -06:00
Ed Page
630e7097fc feat(error: Expose empty value context 2022-02-04 10:01:07 -06:00
Ed Page
0c36fc2073 feat(error): Expose argument conflict context 2022-02-04 09:59:06 -06:00
Ed Page
7029e76545 refactor(error): Prepare for deferring formatting 2022-02-04 09:56:22 -06:00
Ed Page
c002951dc8 refactor(error): Centralize app knowledge 2022-02-04 09:51:34 -06:00
Ed Page
ee63f6cd9b refactor(error): Prepare for optional deferred formatting 2022-02-04 09:45:12 -06:00
Ed Page
af41e8d6b2 refactor(error): Separate try_help concerns 2022-02-04 08:49:55 -06:00
Ed Page
8de99407f9 feat(error): Impl Display for ErrorKind 2022-02-04 08:37:23 -06:00
Ed Page
4add5723ec refactor(error): Don't constrain start of errors
This also makes the intent for the start of an error clearer.
2022-02-04 08:21:24 -06:00
Ed Page
70b830a1ad refactor(error): Prepare for adding more app fields 2022-02-03 13:05:10 -06:00
Ed Page
00af9c11f8 refactor(error): Shift focus to modern fields 2022-02-03 12:59:59 -06:00
Ed Page
27469dc740 refactor(error): Centralize new formatting 2022-02-03 12:36:20 -06:00
Ed Page
1b66585dc2 feat(error): New error context API
This is meant to replace `Error::info` as part of #2628.
2022-02-03 12:30:49 -06:00
Ed Page
59b63aea51 refactor(error): Pull out kind mod 2022-02-02 16:13:26 -06:00
Ed Page
2d01331540 refactor(error): Prepare for splitting mod 2022-02-02 16:06:23 -06:00
Ed Page
03832c75b9 refactor: Reduce reliance on soon-to-deprecate kind 2022-02-02 15:47:47 -06:00
Ed Page
3b516a4d62 perf(error): Reduce stack size of Error 2022-02-02 15:46:45 -06:00
Ed Page
a889797c27 fix(error): Allow Result interoperability 2022-02-02 15:43:07 -06:00
Ed Page
b538a43961 refactor(error): Switch to error::ErrorKind 2022-02-02 15:41:24 -06:00
Ed Page
5535f49d13 fix(error): Expose the error module
We'll be expanding whats included and we shouldn't spam the root as
much.
2022-02-02 15:35:20 -06:00
Ed Page
b55edfa740 refactor: Rename errors mod
It seems that `error` is more common (e.g. `nom`)
2022-02-02 15:34:17 -06:00
Ed Page
9d482d00ba feat(error): Show possible values when none are supplied
This is inspired by cargo which allows you to run `cargo test --test`
and it will list the possible tests (obviously we can't support that atm
because that requires a lot of runtime processing).  When we do have a
static list of possible values, we can at least show those.

Fixes #3320
2022-02-02 14:28:41 -06:00
Ed Page
6827491069 fix(error): Consistently respect possible values order
We respected it for `--help` but not error messages.

Fixes #1549
2022-02-02 13:58:58 -06:00
Ed Page
06aa418fa6 fix(error): Be more accurate in smart usage
For some errors, we use the unroll logic to get the list of required
arguments.  The usage then does the same, but without a matcher.  This
was causing the lists to not match.

As a side effect, this fixed an ordering issue where we were putting the
present arg after the not-present arg.  I assume its because we ended up
reporting the items twice but the first time is correctly ordered and
gets precedence.

This was split out of #3020
2022-02-02 13:30:23 -06:00
Ed Page
d376865c18 refactor: Clarify intent behind requires
This is based on the work in #3384
2022-02-01 16:51:55 -06:00
Ed Page
c0b12c7260 refactor: Clarify intent of default_value_if
While this doesn't help in the public API (yet), this at least clarifies
the intent in the implementation.

This is building towards #3020.
2022-02-01 16:38:05 -06:00
Ed Page
dc035de409 chore: Release 2022-02-01 16:11:53 -06:00
Ed Page
50a58e98eb feat(parser): Check if args were present
In clap2, `ArgMatches.args` was public but hidden.  We made it private
in clap3, giving us more implementation flexibility but many people
relied on it, like to short-circuit defaulting, providing their own
`ArgRequiredElseHelp`, etc.

The main problem was how to expose this
- If we think of `ArgMatches` as a container (a DAG), should we have an
  `is_empty` and what all is included in that, like subcommands?
- If we focus on only args, what term how do we refer to this to convey
  the right intent?

In the end, I realized that this aligns most with our existing
`is_present` check and reporting if args are present fits the best
within the existing API.

I looked into also exposing iterating over the args (`present_arg_ids`)
but we have no way to expose the Id.  The Id is currently private and if
we made it public, it can't be used to access any arg because it can't
implement `Key`.

This supersedes #3265
2022-02-01 15:52:21 -06:00
Ed Page
3722270e47 style: Clippy 2022-02-01 13:56:45 -06:00
Ed Page
c638330e85 refactor: Reduce what Parser visibility we can 2022-02-01 13:44:55 -06:00
Ed Page
05f8151d3d fix(usage): Track all required 2022-02-01 13:38:23 -06:00
Ed Page
232c17ebc4 refactor(help): Decouple from parser 2022-02-01 13:23:58 -06:00
Ed Page
3cd9174f48 refactor(usage): Decouple from the parser
This is a step towards removing `pub(crate)` and for moving usage/help
out of the core clap generally.
2022-02-01 12:42:32 -06:00
Ed Page
ac50402778 refactor: Reduce visibility of PossibleValue members 2022-02-01 11:27:45 -06:00
Ed Page
b2c7572643 refactor: Reduce visibility of MatchedArg members 2022-02-01 11:27:45 -06:00
Ed Page
cd6e009c83 refactor: Reduce visibility of ArgMatcher members 2022-02-01 11:27:08 -06:00
Ed Page
4538d618a7 refactor: Migrate off of .kind 2022-02-01 11:27:08 -06:00
Ed Page
65c9bba85c feat(error): Provide kind()
This is prep for deprecating direct member access but not doing it yet.
2022-02-01 11:27:08 -06:00
Ed Page
7f61869a60 refactor: Reduce visibility on Error members 2022-02-01 11:27:08 -06:00
Jan Verbeek
bfc8e8d367 perf: Do not instantiate Id::from(&&str)
Saves 0.3K.
2022-02-01 17:22:03 +01:00
Jan Verbeek
9e625c0c55 perf: Avoid clone 2022-02-01 17:22:03 +01:00
Jan Verbeek
d1d9f75d53 perf: Make formatting method calls more efficient
If a value must be reused later then it's better to pass it as a &str
instead of cloning it, that means the clone happens in a central
place (inside the method).

By never passing a &String those instances of the method are not monomorphized.

Saves only 0.5K, maybe not worth it in hindsight.
2022-02-01 17:22:03 +01:00
Jan Verbeek
54e8f7eff2 perf: Extract common Error constructor logic
Saves 1.2K.
2022-02-01 17:21:57 +01:00
Jan Verbeek
b2cc41884d style: Use clearer variable name for formatted verb 2022-02-01 17:21:57 +01:00
Jan Verbeek
0dce4b5af2 perf: Split delimited value in single iterator
Saves 0.9K.
2022-02-01 17:21:52 +01:00
Jan Verbeek
9b03495bc6 perf: Format directly into strings
Saves 0.5K (and some allocations).
2022-02-01 17:21:52 +01:00
Jan Verbeek
4420fd25c8 perf: Merge .clone() calls
This seems like something rustc would be able to figure out, but
apparently not.

Saves 0.6K.
2022-02-01 17:21:52 +01:00
Jan Verbeek
6411e2ede6 style: Change format!("{}") → to_string() 2022-02-01 17:21:47 +01:00
Jan Verbeek
2d340dce9e perf: Prefer write_str() over write!("{}")
Saves 1K.
2022-02-01 17:21:47 +01:00
Jan Verbeek
778bcf2ecc perf: Extract non-generic part of App::new()
Saves 5K.
2022-02-01 17:21:47 +01:00
Jan Verbeek
7774a8ee8a perf: Do not clone subcommands
This saves a whopping 8K. I suspect it allows two sorting functions
to be merged.
2022-02-01 17:21:47 +01:00
Jan Verbeek
c77fb2e11d perf: Remove unnecessary clone 2022-02-01 17:21:47 +01:00
Jan Verbeek
14f9ec0ab6 style: Avoid nested unwrap_or 2022-02-01 17:21:47 +01:00
Jan Verbeek
14fa6a73fa perf: Avoid unnecessary String
Saves 0.3K.
2022-02-01 17:21:47 +01:00
Jan Verbeek
b4a2966e51 style: Convert char to string in single operation 2022-02-01 17:21:47 +01:00
Jan Verbeek
b5a8f828b8 style: Use if instead of strange Option::map_or 2022-02-01 17:21:47 +01:00
Jan Verbeek
21f0cd5662 perf: Avoid double reference 2022-02-01 17:21:47 +01:00
Jan Verbeek
0b3ad1735a perf: Avoid unnecessary copies in errors
Saves 3.5K.
2022-02-01 17:21:40 +01:00
Jan Verbeek
6d558c9141 perf: Do not inline get_color()
Saves 1.7K.
2022-02-01 17:21:40 +01:00
Jan Verbeek
3258396738 perf: Do not do verb formatting at runtime
Saves 1K.
2022-02-01 17:21:40 +01:00
Jan Verbeek
0c0d51b29a perf: De-inline another formatting method 2022-02-01 17:21:40 +01:00
Jan Verbeek
82dd01a1df style: Change unwrap_or_else() → or() 2022-02-01 17:21:35 +01:00
Jan Verbeek
29191bf386 perf: Remove another BTreeMap
This is smaller if we do a stable sort.
2022-02-01 00:02:44 +01:00
Jan Verbeek
844e0cde91 perf: Improve display_arg_val() code size
Making it non-generic doesn't seem to help.
2022-02-01 00:02:44 +01:00
Jan-Bernd Vosteen
c78494fd75 added missing 'be' 2022-01-31 14:52:36 +01:00
Wilfred Hughes
f7a2b472a2
Fix typo in doc comment 2022-01-29 16:18:33 -08:00
Jan Verbeek
a18658af86 perf: Replace BTreeMaps by manually sorted Vecs
This removes another ~20KB of code size.

There is one BTreeMap left, but replacing that one doesn't make a difference.
2022-01-29 22:18:32 +01:00
Jan Verbeek
7bf2479125 perf: Do not inline formatting methods
This shaves off ~20KB from the argparse-benchmarks-rs app.
2022-01-29 22:18:30 +01:00
Sondre Nilsen
0b045f5d0d
feat(man): Initial man generator (#3174)
This is an initial implementation with plenty of room to grow, including
- Allowing pulling out a subset of the generated man page for greater customization
- Subcommand handling
- Extra sections
- Consolidate argument formatter after #2914

Fixes #552
2022-01-28 14:55:55 -06:00
Ed Page
d2109b3969 chore: Release 2022-01-26 15:54:12 -06:00
Peter Grayson
7eea7d27ad
fix(help): Optional arg values in brackets
When an Arg uses .min_values(0), that arg's value(s) are effectively
optional. This is conventionaly denoted in help messages by wrapping the
arg's values in square brackets. For example:

    --foo[=value]
    --bar [value]

This kind of argument can be seen in the wild in many git commands; e.g.
git-status(1).

Signed-off-by: Peter Grayson <pete@jpgrayson.net>
2022-01-26 12:03:23 -05:00
Ed Page
ea7699c11f chore: Release 2022-01-24 15:34:27 -06:00
Ed Page
e5b06c3061 chore: Release 2022-01-24 10:54:50 -06:00
Ed Page
c6664afe9d fix(parser): Track the most explicit value source
We were only tracking the last value source (default, env, cli, etc).
This works for args because they only come from one source.  Groups
however can come from multiple sources and this was making us treat a
group with a default value as being completely from defaults despite
some values maybe being from the commandline.

We now track the highest precedence value for a group.

Fixes #3330
2022-01-24 10:34:41 -06:00
Ed Page
43673a1bd1 docs(error): Update reported failure code
Fixes #3332
2022-01-24 08:11:18 -06:00
Ed Page
5877f884f1 chore: Release 2022-01-18 14:59:58 -06:00
Ed Page
38e6952d46 fix: Don't panic when propagating
I thought I was adding a test in #3305.  Maybe I considered the
clap_complete changes sufficient for this.  Doing more `debug_assert`s
would be good also.

Unsetting `PropagateVersion` helps in some cases but we need to unset it
globally to override the global propagation.

Fixes #3310
2022-01-18 14:38:58 -06:00
Ed Page
bd1bf66279 chore: Release 2022-01-17 20:34:09 -06:00
Rain
236ec973d9 feat: Implement App::find_subcommand_mut
Similar to `App::find_subcommand`, except it returns a mutable reference
to the subcommand.
2022-01-17 12:31:41 -08:00
Ed Page
ccbbba8908 chore: Release 2022-01-17 09:37:45 -06:00
Ed Page
ffe6bff8ac
Merge pull request #3305 from epage/help
fix(help): Always respect DisableColoredHelp
2022-01-17 09:35:18 -06:00
Ed Page
4a43b51a42 fix(complete): Handle help completions
The main motivation was to reduce special cases by putting all of the
logic in one place.
2022-01-17 09:23:04 -06:00
Ed Page
e962ad8ce6 fix(help): Always respect DisableColoredHelp
We might be able to handle version/help before propagation but I didn't
want to hold up this fix for that to happen and increase the risk
associated with this fix.

Fixes #3298
2022-01-17 09:14:07 -06:00
Ed Page
807ddbbb70 refactor: Build help subcommand separately 2022-01-17 08:36:37 -06:00
Ed Page
729f4e7e82 refactor: Make subcommand propagation reusable 2022-01-17 08:33:07 -06:00
Ed Page
3620cad5fa
Merge pull request #3297 from kornelski/track_asserts
Track caller on methods using assertions
2022-01-17 08:00:42 -06:00
Zhishi
fbbd70ccc9 docs: Fix mismatched ` 2022-01-17 19:06:22 +08:00
Kornel
0121690f9c Track caller on methods using assertions 2022-01-16 12:45:25 +00:00
Ed Page
3d8ce3f426 chore: Release 2022-01-12 11:12:42 -06:00
Ed Page
b200a869b4
Merge pull request #3288 from epage/assert
fix: Run more parse asserts during build
2022-01-12 11:09:16 -06:00
Ed Page
b98e8ec24f docs(derive): Args doesn't derive IntoApp
Fixes #3284
2022-01-12 10:58:35 -06:00
Ed Page
de275e7cf9 fix: Run more parse asserts during build
This will help prevent issues from being deployed to users like in #3281

I do not consider this a breaking change because any normal operation
will assert anyways.
2022-01-12 10:55:55 -06:00
Ed Page
811fd6a04a chore: Release 2022-01-10 16:16:18 -06:00
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
Ed Page
2eb69def4e fix(error): Ensure trailing newline without help
Fixes #2787
2021-12-13 13:09:48 -06:00
Ed Page
98a1c2e6c9 fix!: Allow adding new enum variants
Without being a breaking change.

This seems minor enough that we can break this during the release
candidates.  For `ValueHint`, the completion scripts are 99% of who
should be `match`ing it.  `AppSettings` as undocumented variants that
people shouldn't use.

BREAKING CHANGE: `clap::{ValueHint, ErrorKind, AppSettings,
ArgSettings}` are now `non_exhaustive`.
2021-12-13 12:11:00 -06:00
Ed Page
be223df828 fix(ci): Correct release lints
I'm assuming we won't have a negative performance impact by removing
`impl Copy for Id` because the compiler would inline the `clone()`s and
turn them into copies.

Addresses problems from #3164
2021-12-13 09:41:22 -06:00
Ed Page
b55ffdd0ce
Merge pull request #3154 from rhysd/fix-unused-warning
Fix unused parameter warning
2021-12-13 09:27:29 -06:00
Richard Maw
38b9645bed fix: Windows Multicall support
The executable suffix is unconditionally stripped off the file path
so that the file name matches subcommands names
without having to add the EXE suffix on different platforms.
2021-12-12 22:08:25 +00:00
Richard Maw
e3d355fa85 feat: Make Multicall just strip dir from argv0 2021-12-12 22:08:25 +00:00
Ed Page
378e8d733d
Merge pull request #3150 from japert/improve-subcommand-deprecation-message
Improve `SubCommand` deprecation message.
2021-12-11 17:42:03 -06:00
Janis Peukert
1f51e8cb2f docs: Clarify deprecation message for SubCommand
Only `SubCommand` is deprecated, not `Subcommand`.
This new deprecation message mentions this ambiguity.

Resolves #3147.
2021-12-11 14:47:08 -08:00
rhysd
b498876cd8 fix: Fix unused parameter warning 2021-12-12 00:44:14 +09:00
rhysd
bc12ef168a feat: Include argument ID in UTF-8 assertion messages
so that users can understand which argument was going wrong.
2021-12-11 15:35:51 +09:00
Ed Page
756f825521 fix: Point to public method on ArgMatches panic
This will make it faster for someone to figure out what is going on
without dropping down to `RUST_BACKTRRACE=1` by giving them the arg
*and* telling them which function *they* called was involved.
2021-12-09 18:51:28 -06:00
Ed Page
264dc37e50 fix: Report if mixing subcommands and args
This is especially helpful for people transitioning off of `is_present`
being used for subcommands.

Fixes #3139
2021-12-09 18:49:51 -06:00
Ed Page
d38452c953 refactor: Clarify explicit display order wins
Now that we use options, we can rely on that, instead of sentinels, for
detecting a default and overriding only a default.

Noticed this as part of looking at #1807.
2021-12-09 16:24:49 -06:00
Ed Page
8a30b01bc1 refactor(yaml): Freeze FromStr 2021-12-09 09:36:00 -06:00
Ed Page
f16bdcc821 fix!: Limit Setting FromStrs to YAML
These exist pretty much just for YAML (#3087).  If anyone else is
building on these, it has a limited shelf-life anyways because of #2717.

BREAKING CHANGE: `FromStr` for settings requires the `yaml` feature.
2021-12-09 09:03:54 -06:00
Ed Page
9d7becca68 docs: Update deprecation messages
- Some still referenced the clapng issue number
- Some YAML ones were missed in the formatting clean up
- I never updated the usage ones with the formatting clean up
2021-12-09 06:47:37 -06:00
Colin Wahl
0b2a04c572 fix: Fix typo 2021-12-08 22:50:18 -08:00
Colin Wahl
f396b28419 chore: Pack exclusive setting into ArgSettings 2021-12-08 22:48:17 -08:00
Ed Page
d42cfee912 docs: Auto-tag feature flags
Fixes #3095
2021-12-08 20:37:53 -06:00
Ed Page
ffa5630de5 docs: Enable lib doc in more cases
Before, we limited it to the `doc` feature because of how extensive the
README was.  It has since scaled back, so we can be more selective with
what features enable it.
2021-12-08 20:37:50 -06:00
Ed Page
e98253dd4a fix: Rename 'doc' feature
This is prep for potentially other 'doc' changes
2021-12-08 20:10:47 -06:00
Ed Page
e5997c1001 docs: Clarify deprecations 2021-12-08 11:14:47 -06:00
Ed Page
76828fada8 docs: Guide people to missing_docs lint 2021-12-07 21:22:12 -06:00
Ed Page
e9b19d676b
Merge pull request #3078 from epage/fixes
Misc fixes from clapng fork review
2021-12-07 21:02:39 -06:00
Ed Page
7f54ecfd0a fix: Deprecation notice for UnifiedHelpMessage,
I missed this in my previous sweeps for re-adding-but-deprecating
Settings.
2021-12-07 18:27:32 -06:00
Ed Page
093de2b83b docs: Add back in logo 2021-12-07 17:45:57 -06:00
Ed Page
e3da325b5a docs: Link out to the crate_ macros 2021-12-07 17:45:57 -06:00
Ed Page
26bbe606d3 Revert "Revert "Revert "docs: Clarify corner caseses with default values"""
This reverts commit 98f696c0a6.

This was previously missed.  See #3076
2021-12-07 17:45:57 -06:00
Ed Page
c1033a3d7a refactor: Simplify Arg::new 2021-12-07 17:45:57 -06:00
Ed Page
4a5d52350e docs: Update old repo location 2021-12-07 08:14:41 -06:00
Ed Page
b2836c07a7 fix: Gracefully handle empty authors 2021-12-06 11:30:26 -06:00
Ed Page
c23f9230d1 chore: Remove stale boiletplate 2021-12-06 11:04:41 -06:00
Ed Page
8595357542 chore: Only error for warnings in CI
This makes it easier for developers to iterate, not having to stop to
write docs just to get things building.
2021-12-06 11:03:14 -06:00
Ed Page
b46abb7236 docs: Re-order items in docs
This contains two types of re-ordering:
- Internal, putting the focus of each file first.
- Public, re-arranging items and grouping impl blocks to try to better
  organize the documentation and find related items.

The main weakness of the docs work is in `Args`.  Its just a mess.  In
particular, we should probably link the simple casesm like `required` to
the advanced impl block.

Fixes #55
2021-12-04 19:18:28 -06:00
Pavan Kumar Sunkara
cc2dddba8e Add DisableColoredHelp setting to improve flexibility (clap-rs/clap#2956)
Until we have a modular help generator that can be configured and/or
authored by the users themselves as part of #2914, we will provide the
flexibility of turning off colored help messages but still wanting
colored error messages.

This flexibility was available before #2845 and @dbrgn immediately
noticed it and requested it back to which I agree. This was also
suggested by Josh in
[here](https://github.com/clap-rs/clap/issues/2806#issuecomment-933877438)
2021-12-04 12:00:46 -06:00
Ed Page
0cd16c34fc feat: App::debug_assert test helper
This will especially be important for users migrating from clap2 so they
can catch problems earlier in the process.
2021-12-03 14:12:03 -06:00
Ed Page
500def4904 fix(derive): Smooth out transition for structopt
Adding in a `StructOpt` derive with `structopt` attributes, with
deprecation notices.  Unofrtunately, not as many deprecation warnings as
I would like.  Apparently, you can't do them for a `use` of a derive?  I
also wanted to inject code that would trigger a deprecation notice for
attributes but that would require enough of a refactor that I didn't
consider it worth it.  We are at least providing a transition window
even if it means we'll have to remvoe it next major release without a
deprecation warning.
2021-12-02 20:18:33 -06:00
Ed Page
75d417851b docs: Clean up 3.0 changelog 2021-12-02 16:07:43 -06:00
Ed Page
3f9da04744 fix: Revert as much yaml policy to v2 as possible 2021-12-02 16:06:21 -06:00
Ed Page
0294fd0170 revert: Bring back ArgSettings::Global
This is a partial revert of cacc23473.  It appears that the deprecation
of `ArgSettings::Global` was never followed through on.
2021-12-02 16:06:21 -06:00
Ed Page
c93809271c fix: Deprecate, rather than obsolete, some App functions 2021-12-02 16:06:21 -06:00
Ed Page
c8254918d6 fix: Add back arg_enum 2021-12-02 16:06:21 -06:00
Ed Page
e065d1dd79 fix: Fix deprecated function name 2021-12-02 16:06:21 -06:00
Ed Page
d876f306eb fix: Add back in write_version 2021-12-02 16:06:21 -06:00
Ed Page
0d1f34b91d fix: Finish reverting clap_app 2021-12-02 10:45:10 -06:00
Ed Page
83abb24002 fix: Remove EmptyValues
The intention had been to that people setting this would now set
nothing.  Unfortunately, clap2 had `EmptyValues` as the default, so
people were more likely to unset it, making this not work out.
2021-12-02 09:59:41 -06:00
Ed Page
267de95bee fix: Change app_from_crate default separator
`":"` isn't ideal, so let's make it at least `"," `.

BREAKING CHANGE: Changed `app_from_crate!()` to use `", "` separator for
authors.
2021-11-30 14:56:17 -06:00