Commit graph

845 commits

Author SHA1 Message Date
Ed Page
95c812b411 feat(builder): Set/Append Actions
This round out the new style actions and allow us to start deprecating
occurrences.

As part of an effort to unify code paths, this does change flag parsing
to do splits.  This will only be a problem if the user enables splits
but we'll at least not crash.  Once we also address #3776, we'll be able
to have envs all work the same.
2022-06-01 10:12:44 -05:00
Ed Page
c58a802a1d style: Make clippy happy 2022-06-01 06:45:23 -05:00
Ed Page
2e9e556359 test(parser): Ensure conditional requirements work with new Actions 2022-05-31 21:21:50 -05:00
Ed Page
4afd1aafe5 fix(parser): Don't double-increment index on flags 2022-05-31 21:21:50 -05:00
Ed Page
06ea572770 fix(parser): Apply conditional defaults
Now that we can store constants for flags, we can apply defaults for
flags too.

Fixes #3294
2022-05-31 21:21:50 -05:00
Ed Page
70b633b0ea refactor(parser): Be explicit about not not iterating over every value 2022-05-31 14:44:36 -05:00
Ed Page
5a55f4a863 fix(parser): Restore positional occurrence behavior
This fixes a compatibility issue introduced in 9805fdad1b
2022-05-31 14:44:36 -05:00
Ed Page
cb6f7b783a fix(parser): Restore interleaved positional behavior
If we felt this was important long-term, we should fix this outside of
the Action.  Since we might be changing up occurrences (#3772), we can
probably get away with a hack.
2022-05-31 14:15:57 -05:00
Ed Page
f2a219e77d refactor(parser)!: Switch flag values to Actions
This changes how occurrences and values are grouped for multiple values.
Today, it appears as a bug.  If we move forward with #3772, then this
can make sense.
2022-05-31 14:04:12 -05:00
Ed Page
bba83cb2af test(parser): Verify interleaved group behavior 2022-05-31 14:00:48 -05:00
Ed Page
c72f03e53f refactor(parser): Be more explicit in default_missing_values
I wrote these tests expecting to highlight a bug but it turns out things
were structured just right to not exhibit it.  The fact that the code
looks like its broken is a problem, so I restructured it (put it first,
changed the source) so it doesn't look suspicious anymore.
2022-05-27 07:04:24 -05:00
Ed Page
302bf63678 fix(parser): Always use delimiter on defaults/env
Doesn't make sense to respect how the command line ended
2022-05-26 20:50:44 -05:00
Ed Page
ccc809a9df fix(parser): Allow delimiting default_missing_values
Fixes #3761
2022-05-26 20:36:49 -05:00
Ed Page
9805fdad1b refactor(parser)!: Consolidate group/occurrence logic
We were independently starting occurrences and starting value groups.
Now we do them at the same time.

COMPATIBILITY: This changes us from counting occurrences per positional
when using `multiple_values` to one occurrence.  This is user visible
and tests were written against it but it goes against the documentation
and doesn't quite make sense.
2022-05-26 19:30:29 -05:00
Ed Page
f082f499ea fix: Remove deprecation warning 2022-05-26 15:52:35 -05:00
Ed Page
ae97550638 fix(validator): Deprecate validator_regex
Fixes #3743
2022-05-25 14:32:00 -05:00
Ed Page
408ca3c5d7 test(derive): Update for deprecations 2022-05-25 13:13:22 -05:00
Ed Page
a712adefcd fix(parser): Deprecate value_of and friends 2022-05-25 12:57:11 -05:00
Ed Page
256643f8d3 fix: Deprecate possible_values 2022-05-25 12:57:11 -05:00
Ed Page
573d496bc6 fix: Deprecate forbid_empty_values 2022-05-25 12:57:11 -05:00
Ed Page
177511dab1 fix: Deprecate validator / validator_os
`validator_regex` is being ignored for now as I await on a comment
period for #3743
2022-05-25 12:57:11 -05:00
Ed Page
f15a1aab1a fix: Deprecate allow_invalid_utf8 2022-05-25 12:57:11 -05:00
Ed Page
15616bbd13 fix(error): Remove usage from value validation
When to show usage?  We are currently mixed about it.  For `validator`,
we didn't show it at all.  Sometimes we show the used arguments and
sometimes we don't.

With `ValueParser`, I ran into the problem that we weren't showing the
used arguments like we had previously in some cases.  In deciding how to
solve this, I went with the simplest route for now and removed it as the
usage likely doesn't add much context to help people solve their
problem, more so the recommendation for help.  We'll see how the
feedback is on this and adjust.
2022-05-23 20:56:04 -05:00
Ed Page
a35df14caf feat(derive): Opt-in to inferred value_parser 2022-05-20 19:25:20 -05:00
Ed Page
b52c7f115e feat(derive): Allow users to opt-in to ValueParser
For clap 3, its opt-in as a precaution against breaking
compatibility in some weird cases.

This does require the types to implement `Clone`.

Fixes #3734
Fixes #3496
Fixes #3589
2022-05-20 15:38:44 -05:00
Ed Page
e0e7383300 test: Re-enable ui tests
`derive_ui.rs` did not have a marker for needing to be updated on MSRV
changes, so it got missed.
2022-05-20 14:10:32 -05:00
Ed Page
686b0379ce feat(multicall): Stablize multicall
`multicall` allows you to have one binary expose itself as multiple
programs, like busybox does.  This also works well for user clap for
parsing REPLs.

Fixes #2861
2022-05-20 12:20:40 -05:00
Ed Page
1a2b7acd60 test(multicall): Conditionalize suggestion-related case
This impacts the error code (#3676) and the error body and without
suggestions, its redundant.
2022-05-20 12:20:40 -05:00
Ed Page
d826ab9445 fix(derive): Move args to new 'get_one'/'get_many' API 2022-05-16 15:16:51 -05:00
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