Commit graph

816 commits

Author SHA1 Message Date
Ed Page
dcf69d1c87 refactor(parser): Track str/OsStr values via Box
Unfortunately, we can't track using a `ValueParser` inside of `Command`
because its `PartialEq`.  We'll have to wait until a breaking change to
relax that.

Compatibility:
- We now assert on using the wrong method to look up defaults.  This
  shouldn't be a breaking change as it'll assert when getting a real
  value.
- `values_of`, et al delay panicing on the wrong lookup until the
  iterator is being processed.
2022-05-12 16:13:30 -05:00
Ed Page
17c99d2878 test(derive): Unsure why this is failing 2022-05-12 06:23:38 -05:00
Ed Page
2e3540355a fix(derive): Don't change case of Arg id's (unstable)
This will make it easier to reference arguments with different
attributes.

Fixes #3282
2022-05-09 10:36:03 -05:00
Ed Page
f7e4dd23d6 refactor(derive): Divide rename_all assertions 2022-05-06 16:47:52 -05:00
Ed Page
ddc9d54f41 refactor(derive): Generalize test name 2022-05-06 16:45:03 -05:00
Ed Page
fe4888d668 refactor(derive): Group subcommand rename tests 2022-05-06 16:43:23 -05:00
Ed Page
65538e21a8 fix(derive): Detect escaped ambiguous subcommands (unstable) 2022-05-06 15:46:34 -05:00
Ed Page
20ff4ce05a doc(parser): Document external subcommand escaping behavior 2022-05-06 12:38:23 -05:00
Ed Page
03f132129b fix(parser): Always put in arg "" for external subcommands (unstable)
This allows distinguishing external subcommands from built-in
subcommands which can especially be confusing when escaping subcommands.

Fixes #3263
2022-05-06 12:25:20 -05:00
Liu Dingming
1b63fbd6df feat(derive): Start unstable-v4 feature flag
This is split out of #3661 as several changes I'm working on need it.
2022-05-06 14:56:55 -05:00
Ed Page
089f96eb87 fix(help): Disallow too many value names (unstable)
I can't think of a case for this or a way to render it.

Fixes #2695
2022-05-06 13:54:07 -05:00
Ed Page
70c29e3dd8 fix(help): Use '...' when not enough value names supplied 2022-05-06 13:33:17 -05:00
Evgeniy Terekhin
229b44d9bb
fix(macros): Allow dashed values (#3699)
add support for dashed arg names and values in arg! macro
2022-05-06 10:58:00 -05:00
Ed Page
e23c786f62 refactor(help): Remove redundant required check
With us moving the required de-duplication up a level, it made this
check redundant.  By removing this check, we're more likely to have an
item in the `incls` which forces a smart usage and reduces the chance of
an `[ARGS]` or `[OPTIONS]`, so a couple of tests changed.
2022-05-05 17:02:49 -05:00
Ed Page
dedbabd402 fix(error): Don't duplicate args in usage
Gave up trying to decipher the existing logic for safe ways to
de-duplicate manually and switched to an `IndexSet` to enforce only one
of each argument exists.

Fixes #3556
2022-05-04 11:05:37 -05:00
Ed Page
16791ab0a7 test(help): Update for display name change 2022-05-04 20:46:49 -05:00
Ed Page
c7ff695581 fix(help): Don't wrap URLs
Confusingly, there are two similar but slightly different settings in
`textwrap`.  We need both set.

Fixes #3222
2022-05-04 16:00:08 -05:00
Ed Page
d3e36b1c90 fix(v4): Disallow leading dashes in long's
This is a step towards #3309.  We want to make longs and long aliases
more consistent in how they handle leading dashes.  There is more
flexibility offered in not stripping and it matches the v3 short
behavior of only taking the non-dash form.  This starts the process by
disallowing it completely so people will catch problems with it and
remove their existing leading dashes.  In a subsequent breaking release
we can remove the debug assert and allow triple-leading dashes.
2022-05-04 15:38:08 -05:00
Ed Page
61b8bbd218 fix(parser): Exclusive overrides required
`Arg::exclusive` is just another way of defining conflicts, so a
present-exclusive arg should override required like other conflicts.

Instead of going through the message of enumerating all other arguments
as exclusive, I shortcutted it and special case exclusive in the
required check like we do with conflicts.  The big downside is the
implicit coupling between the code paths rather than having a consistent
abstraction for covering conflicts.

This isn't a breaking change because if someone defined an exclusive arg
as a sibling to a required arg, the exclusive arg could never be used,
it always errored, and so no valid application can be written with it.

Fixes #3595
2022-05-04 12:25:44 -05:00
Ed Page
3cfea3223b fix(help): Offer a html_template variable for display name
This is a step towards #992.  When help renders the application name, it
uses the `bin` template variable which is just the `bin` name with
spaces converted to ` `.  While having `app.exe sub` makes sense,
`app.exe-sub` does not.

To get around needing this for usage, we've created a `display_name`
field that is fairly similar but
- The root name is the `name` and not `bin_name`
- We always join with `-`

This means that the derived `bin_name` will only show up in usage.

For now, the default template has not been updated as that is a minor
compatibility change and should be in a minor release, at least.  I was
worried this would be a full breaking change.  The main case I was
worried about was cargo subcommands but our tests show they should just
work.
2022-05-03 14:34:47 -05:00
Ed Page
af3b789e4c fix(multicall): Consistently skip multicall bin in help 2022-05-02 11:50:30 -05:00
Ed Page
8cd59fa4e5 fix(multicall): More consistent whitespace in errors 2022-05-02 11:01:14 -05:00
Ed Page
f9fdb99ee8 fix(multicall): Disallow args on multicall binary
Set expectations for how this can be used and to make sure the right
errors are given.
2022-05-02 09:33:09 -05:00
Ed Page
ce727f1951 fix(error): Render actual usage for unrecognized subcommands
For some reason this code path diverged and manually constructed a
usage, not following any of our patterns for doing so.
2022-05-02 09:25:44 -05:00
Ed Page
5cd1a4070b fix(multicall): Show subcommands are required 2022-05-02 09:13:44 -05:00
Ed Page
414ae57a2a fix(multicall): Improve bad multicall binary error
By removing all arguments, we've switched from an "unrecognized
argument" error to a "unrecognized subcommand" error.  While the wording
has room for improvement, its at least progress on #2862.
2022-05-02 09:12:12 -05:00
Ed Page
ff53b087e0 chore: Remove dead code 2022-05-02 05:52:18 -05:00
Ed Page
0ecb6f4869 fix(builder): Fully recurse when building
Besides addressing the panic from assuming things were built when they
weren't, this should fix some completion issues for some people.

Fixes #3669
2022-04-30 20:02:06 -05:00
Ed Page
ccf8634c19 fix(help): Provide correct context for help subcmd errors 2022-04-29 20:25:05 -05:00
Ed Page
1452c1e42b fix(help): Help subcommands usage includes requires arguments 2022-04-29 20:16:19 -05:00
Ed Page
37ebb71806 fix(help): write_help usage includes required arguments 2022-04-29 20:15:54 -05:00
Ed Page
2edc1a2bdf test(help): Verify showing of required attributes 2022-04-29 15:46:15 -05:00
Ed Page
7cdce9cabe refactor(test): Use snapbox's diffs 2022-04-29 15:32:25 -05:00
Ed Page
1e2471649e test(output): Ensure correct streams
This is to prevent #3648 from happening again
2022-04-22 10:56:47 -05:00
Ed Page
e7471eb546 test(group): Verify overrides required
This adds a test for de89c050c9 that
confirms #3647 is fixed

Fixes #3647
2022-04-22 07:01:53 -05:00
Ed Page
a484f622de fix(validate): Overrides always ignore required
Before, if two arguments were required *and* overrode each other, then
`cmd --opt=1 --other=2` succeded but `cmd --other=2` failed despite
ignoring `--opt=1`.  Requiring `--opt=1` to be present but unavailable
doesn't help anyone and makes the behavior less predictable.

Now both commands will have the same behavior.
2022-04-21 15:23:05 -05:00
Ed Page
8f182067e3 feat(clap): Publicly expose Command::build
`Command::_build_all` started as an internal function for
`clap_complete` as a stopgap until #2911.  Overtime, we've been finding
more cases where this function needs to be called, so now we're going to
fully embrace it until #2911 so people aren't scrared off by the hidden
implementation from using it.

This was inspired by #3602

Comptibility: Though this adds a deprecation which we general reserve
for minor or major versions, this is enough of a corner case that I'm
fine doing this in a patch release.
2022-04-19 10:13:43 -05:00
shir0kamii
fb4755d1c3 feat(derive): Don't abort when non-unit variant is skipped 2022-03-31 18:49:21 +02:00
shir0kamii
ee3d12ec56 fix(derive): Abort on non-unit variant 2022-03-30 03:49:14 +02:00
plaflamme
154c0d0c65
test: Add test to demonstrate regression 2022-03-06 23:09:55 -05:00
Roland Fredenhagen
33949ce4de
feat(help): Show PossibleValue help in --help (#3503)
`-h` (short help) still shows the same.

This gates it behind an `unstable-v4` feature flag to avoid disrupting users who set the help without knowing where all it shows up (particularly derive users where `ArgEnum` is automatically extracting the help).

Fixes #3312
2022-03-02 09:15:28 -06:00
Ed Page
3f2a37088b fix(assert): Validate delimited defaults
Fixes #3514
2022-02-28 09:21:44 -06:00
Ed Page
cb937641fa fix(derive): Allow other attributes with subcommand that has subcommands
This was overlooked when we added support for `#[clap(subcommand)]` to
variants.

Fixes #3504
2022-02-23 09:23:33 -06:00
Ed Page
976f3d500a
Merge pull request #3473 from epage/derive
fix: Change `IntoApp::into_app` to `CommandFactory::command`
2022-02-15 09:33:44 -06:00
Ed Page
360c4d6b8a docs: Update to new command! macro 2022-02-15 08:54:59 -06:00
Ed Page
65b9c88b3c fix: Update app_from_crate for App rename
Instead of just renaming it, I reconsidered what the API should look
like.  A custom separator for author does not make sense positionally
but accepting a name, and defaulting it, does fit with what someone
would expect.

I removed the `_from_crate` suffix because it doesn't seem necessary.
We don't have this kind of naming for the derive.  I feel it cleans
things up this way.
2022-02-15 08:39:07 -06:00
Ed Page
ddac492302 fix: Rename IntoApp to CommandFactory
This is part of the `App` rename.

Previously, I was concerned about not being able to deprecate

For backwards compatibility, we still expose the `IntoApp` name.
2022-02-15 08:24:00 -06:00
Ed Page
7aa45667f5
Merge pull request #3472 from epage/cmd
fix: Rename App to Command
2022-02-15 07:55:36 -06:00
Maarten de Vries
bd68653248 test: Add UI test for unsupported parsers 2022-02-15 12:00:25 +01:00
Ed Page
3475555de6 fix(help): Use standard alternate syntax for subcommands 2022-02-14 21:18:33 -06:00