Commit graph

2389 commits

Author SHA1 Message Date
Pavan Kumar Sunkara
301c6f765a Added and used ArgPredicate api 2021-11-11 22:33:30 +00:00
Pavan Kumar Sunkara
43a4c90c86 Remove is_default_value in favor of contains_explicit_value 2021-11-11 22:07:29 +00:00
Pavan Kumar Sunkara
4e29777b21 Added contains_explicit_val function instead of contains_val 2021-11-11 22:07:29 +00:00
Pavan Kumar Sunkara
69957c4ddd Revert "Revert "Fixes arg having required_unless on default values""
This reverts commit 6e85fb3ae0.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
bdb1d324a5 Revert "Revert "Fixes arg having required_if on default values""
This reverts commit 8818327b25.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
b102da0cd2 Revert "Revert "Fixes arg and group with default value having requires""
This reverts commit bd8c36cf04.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
72429be14e Revert "Revert "Fixes group conflicting if two args with default values""
This reverts commit 4e370bb093.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
0b7def675b Revert "Revert "Fixes arg conflicting with group whose arg has default value""
This reverts commit 706085d9c5.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
b86aa631be Revert "Revert "Fixes group conflicting with arg which has default value""
This reverts commit 736cb28dd0.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
6b458c602d Revert "Revert "Added ArgMatcher::is_default_value abstraction""
This reverts commit 5e76e6c568.
2021-11-11 21:33:50 +00:00
Pavan Kumar Sunkara
45f281b67e Revert "Revert "Revert "docs: Clarify corner caseses with default values"""
This reverts commit 98f696c0a6.
2021-11-11 21:33:50 +00:00
Ed Page
a2c3b14bb0 fix(app): Propogate color
In #2851, we moved color from an AppSetting to function (with some
tweaks in #2907).  When doing this, we documented `App::color` to be
equivalent of `App::global_settings(Color...)` but never actually
propagated it.

We are now propagating it.  A test is added to ensure that no matter
how we store the color choice, we continue to propagate it.  This
required exposing `App::get_color`.
2021-11-11 11:39:21 -06:00
Ed Page
ae67496473 feat(app): Expose App::get_color
This will be important for testing color support.  No idea how much
users will care.
2021-11-11 11:34:20 -06:00
Ed Page
839ad67b6b Revert "Add App::mut_args"
This reverts commit 6e4ac4cffc.
2021-11-05 09:29:38 -05:00
Ed Page
23b1502c00 Revert "Fix docs variable name"
This reverts commit 0dded91541.
2021-11-05 09:28:23 -05:00
Ed Page
4b0048666a fix: Allow unicode aware case insensitivity
In #2985, I noticed #2834 was incomplete, there were case-insensitive
comparisons we were doing without being unicode aware (when compile
options are set).

The downside is that each comparison will require a UTF-8 validation.
These seem to be in more of corners of the API, rather than in common
calls in common usages, so hopefully that isn't too much of a problem.
2021-11-04 12:23:02 -05:00
bors[bot]
879dd23963
Merge #2986
2986: Revert #2950 to make sure we get it properly in #2985 r=epage a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-11-03 18:51:19 +00:00
Pavan Kumar Sunkara
98f696c0a6 Revert "Revert "docs: Clarify corner caseses with default values""
This reverts commit 4edcda2b99.
2021-11-03 18:27:12 +00:00
Pavan Kumar Sunkara
5e76e6c568 Revert "Added ArgMatcher::is_default_value abstraction"
This reverts commit 261a2c00e8.
2021-11-03 18:26:15 +00:00
Pavan Kumar Sunkara
736cb28dd0 Revert "Fixes group conflicting with arg which has default value"
This reverts commit 8c76556ac4.
2021-11-03 18:25:53 +00:00
Pavan Kumar Sunkara
706085d9c5 Revert "Fixes arg conflicting with group whose arg has default value"
This reverts commit 64a2866b09.
2021-11-03 18:25:25 +00:00
Pavan Kumar Sunkara
4e370bb093 Revert "Fixes group conflicting if two args with default values"
This reverts commit 01869744c2.
2021-11-03 18:24:50 +00:00
Pavan Kumar Sunkara
bd8c36cf04 Revert "Fixes arg and group with default value having requires"
This reverts commit 130dcbfdd9.
2021-11-03 18:22:19 +00:00
Pavan Kumar Sunkara
8818327b25 Revert "Fixes arg having required_if on default values"
This reverts commit a88562c12b.
2021-11-03 18:20:39 +00:00
Pavan Kumar Sunkara
6e85fb3ae0 Revert "Fixes arg having required_unless on default values"
This reverts commit ac1de1fc78.
2021-11-03 18:18:54 +00:00
bors[bot]
3cc46a1c83
Merge #2984
2984: fix: Switch sub-commands from multi-val to multi-occur r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-11-03 16:59:25 +00:00
Ed Page
8212647bb3 fix: Switch sub-commands from multi-val to multi-occur
Similar to #2977, this changes positional argument `<subcmd>` in
`help <subcmd>` to be multiple occurrences, from being multiple values.

This is what identified the usage generation bug fixed in #2978 and was
isolated into the test case `positional_multiple_occurrences_is_dotted`.

This is part of #2692 where we re-evaluate the usage of multiple values
for positionals now that we accept multiple occurrences.
2021-11-02 20:55:43 -05:00
bors[bot]
ae48175207
Merge #2977
2977: fix(usage)!: Switch positionals... from multi-val to mulit-occur r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-11-03 01:47:44 +00:00
bors[bot]
9365f6a0af
Merge #2907
2907: fix: Ease clap2->3 transition for Settings r=kbknapp a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-11-03 00:41:14 +00:00
Ed Page
66341b3c11 fix: Always respect positional occurrences
When supporting multiple occurrences for positional arguments in #2804,
I added some tests to cover this but apparently simpler cases fail
despite those more complicated cases being tested.

This adds more multiple-occurrences tests for positional arguments,
fixes them, and in general equates multiple values with occurrences for
positional arguments as part of #2692.  There are a couple more points
for consideration for #2692 for us to decide on once this unblocks them
(usage special case in #2977 and how subcommand help should be handled).

I fully admit I have not fully quantified the impact of all of these
changes and am heavily relying on the quality of our tests to carry this
forward.
2021-11-01 14:14:04 -05:00
Ed Page
ade6028da1 fix: Loosen reflection lifetimes
Though we store a lot of values as `&'help str`, we return them as
`&'self str`, making it so they can not be used programmatically as part
of a `App::mut_arg` call.

This loosens the lifetimes so they can be used with `App::mut_arg`.
This also includes a test simulating the desired workflow described in #2966

I skipped `get_all_aliases`.  I ran into problems with lifetimes with
`all_subcommand_names`  and didn't quickly resolve it.  Rather than hold
this up, I punted on it for now.

We'll have to tighten these back up with #1041 but that will also enable
turning them into owned strings, so this will still be possible after
that issue is resolved, just the calls will be slightly different.
2021-11-01 16:28:43 -05:00
Ed Page
dd2c4c6346 fix(usage)!: Switch positionals... from multi-val to mulit-occur
I noticed this while investigating #2692.  Since we are making
multiple-occurrences a thing for positional arguments, this allows us to
remove a special case.

Another way to look at this is that we should make the default whatever
we do for dervies (#1772).  I'm going to propose we make the derive
always turn `Vec<i32>` into multiple occurences and not multiple values
(with users being able to change it through attributes), but that is an
in-work proposal and not decided yet.

BREAKING CHANGE: `Arg::from(...)` will now use `multiple_occurrences`
for a positional `...`, rather than `multiple_values`.
2021-11-01 12:15:00 -05:00
bors[bot]
96e7dfeb43
Merge #2969
2969: refactor: Allow partially used genned code r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-31 10:32:32 +00:00
Ed Page
53bd42a809 fix(usage)!: Separate mutli-occ from multi-val syntax
In looking at multiple occurrences and values for issues like #2692, I
noticed that `...` can mean both multiple values and multiple
occurrences, like before we split them.

Pros
- No syntax change with clap3

Cons
- All the reasons we split `multiple` into two

Uncertain
- I originally started this as part of another branch but I lost track
  if something depended on this.  I'll have to do more digging

BREAKING CHANGE: If `--opt [val]...` was meant for
- only multiple occurrences, see `[opt]... --opt [val]`
- both multiple occurrences and values, see `[opt]... --opt [val]...`
2021-10-30 12:56:49 -05:00
bors[bot]
dfa4690c96
Merge #2972 #2973
2972: refactor: Remove unused variable r=pksunkara a=epage



2973: test(usage): Make cases more consistent r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-30 18:05:11 +00:00
Ed Page
92df0ba263 test(usage): Make cases more consistent
Besides being more explicit / clear, this makes it easier to experiment
with tweaking the logic and keeping the test updates minimal, so the
change of behavior stands out more.
2021-10-30 12:11:49 -05:00
bors[bot]
0e674bcb48
Merge #2968 #2971
2968: test(derive): Provide better error info r=pksunkara a=epage



2971: Fix grammar in doc comment r=epage a=QuantumCoded



Co-authored-by: Ed Page <eopage@gmail.com>
Co-authored-by: Jeffrey <QuantumCoded@users.noreply.github.com>
2021-10-30 16:53:07 +00:00
Ed Page
7661f1f50d refactor: Remove unused variable 2021-10-30 11:46:39 -05:00
Jeffrey
d6c2ab4891
Fix grammar in doc comment
Added space after period in doc comment for `subcommand_name`
2021-10-30 10:37:14 -05:00
Ed Page
391980286e refactor: Allow partially used genned code
Wow, I'm having a hard time summarizing this for the summary.

When we code-gen Settings using `impl_settings`, we have no control over
whether one instance of a Settings will use some or all functions.  I
have a fix that removes the one `ArgSettings::unset`, causing warnings
for `ArgSettings` despite needing it for `AppSettings`.

So I'm making it less dependent on how each instantiation uses it.
2021-10-30 10:29:39 -05:00
Ed Page
ca29e4760c chore(error): Remove unused backtrace warning
Technically, this also fixes a bug with an extra newline when building
with `debug` but that is a pretty minor cosmetic issue.  It is unclear
if `backtrace` has a trailing newline or not, so I left that as-is.
2021-10-30 09:26:37 -05:00
bors[bot]
b42e2baf59
Merge #2967
2967: fix(derive): Support WaitOnError for derive-genned errors r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-30 14:20:27 +00:00
Ed Page
21cc39678b fix(derive): Support WaitOnError for derive-genned errors
Before, `Error::exit` didn't provide `WaitOnError`, requiring each call
site to duplicate half of `Error::exit`s behavior to get it.  This
hadn't been done for errors raised by derive-generated code.  Ideally,
these errors never happen but all the same, having this consistent would
be good.

This moves knowledge of `WaitOnError` to `Error` (including through
`Error::format`) so `Error::exit` can wait.  Now all of the callers to
`.exit` get a consistent experience without duplication.

While #2938 made a lot of `Error` fields optional for less churn-heavy
modifications, I made this new field required to minimize the risk of an
raise site forgetting to set it.
2021-10-30 09:08:11 -05:00
Johan Andersson
0dded91541
Fix docs variable name
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-30 12:55:46 +02:00
Johan Andersson
6e4ac4cffc Add App::mut_args 2021-10-30 12:26:15 +02:00
Ed Page
6126f998d1 fix(error): Never show unrequested color
If the user prints a raw error, it may include color even if the user
turned it off at runtime.  Now we'll be more conservative and never show
color for raw errors.

This is a follow up to #2943; apparently I had missed some cases.
2021-10-29 16:28:23 -05:00
Pavan Kumar Sunkara
92977060be
Allow r_unless_all to be used along with r_unless_any 2021-10-28 00:10:30 +01:00
bors[bot]
0d7a0a81c2
Merge #2950
2950: Fix default value behaviour with conflicts and requirement validation r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-27 20:16:21 +00:00
Ed Page
4835c00419 fix: Ease transition for now-default settings
We prefer Settings to always be off by default, so when we change a
default, we have to rename.

This adds back in the now-default settings with deprecation messages to
help the user know how things now work.

Unfortunately, there is no way to notify the user that the default they
relied on has changed.  This also doesn't help us when the change in
behavior is more than just an inverting, like `InvalidUtf8` or when a
setting mapped to multiple bits.
2021-10-27 13:07:06 -05:00
Ed Page
99058014d8 fix: Allow using deprecated color AppSettings
This partiall reverts commit efeb02cd34,
bringing back the `AppSettins::Color*` and making them the backing store
for `App::color`, to help ease the transition from clap2->3.

Once we remove these deprecated settings, we might want to keep this
backing store to save on memory.

This is a part of #2617
2021-10-27 13:07:06 -05:00
Ed Page
88b89317ab fix: Ease clap2->3 transition with renamed Settings
This brings back the old name of settings, just deprecated.  Since they
all map to the same bits in the bit field, this should work for
`setting` and `is_set`.  The only thing this lacks is being able to do
equality across variants, whcih seems like a minority case.

Removed settings have some extra care abouts that we'll need to look
into separately.

This is a part of #2617
2021-10-27 13:07:06 -05:00
bors[bot]
281eba244d
Merge #2000
2000: Make methods from ArgMatches panic on unknown argument r=pksunkara a=CreepySkeleton



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-27 09:23:04 +00:00
Pavan Kumar Sunkara
0cbec63489 Make sure that ArgMatches methods panic on unknown arg, not return false 2021-10-27 02:42:30 +01:00
bors[bot]
a802662341
Merge #2952 #2953
2952: fix(derive): Don't duplicate subcommand aliases r=pksunkara a=epage



2953: docs(app): Correlate help_heading and subcommand_placeholder r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-26 21:56:54 +00:00
Pavan Kumar Sunkara
ac1de1fc78
Fixes arg having required_unless on default values 2021-10-26 22:27:10 +01:00
Ed Page
f3fec3ed0f docs(app): Correlate help_heading and subcommand_placeholder
This is to increase the chance a user discovers what they are looking
for, by using similar terms and cross-linking.
2021-10-26 16:21:02 -05:00
Pavan Kumar Sunkara
a88562c12b
Fixes arg having required_if on default values 2021-10-26 22:18:01 +01:00
Pavan Kumar Sunkara
130dcbfdd9
Fixes arg and group with default value having requires 2021-10-26 22:18:01 +01:00
Pavan Kumar Sunkara
c4fdb1dd42
Improve requirements validation by removing dead code 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
01869744c2
Fixes group conflicting if two args with default values 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
64a2866b09
Fixes arg conflicting with group whose arg has default value 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
8c76556ac4
Fixes group conflicting with arg which has default value 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
261a2c00e8
Added ArgMatcher::is_default_value abstraction 2021-10-26 22:18:00 +01:00
Pavan Kumar Sunkara
bf91a1a35a
Improve debug assert for required group and default value interaction 2021-10-26 22:17:59 +01:00
Pavan Kumar Sunkara
4edcda2b99
Revert "docs: Clarify corner caseses with default values"
This reverts commit 45ef0722f3.
2021-10-26 22:17:59 +01:00
bors[bot]
f9e074e554
Merge #2926 #2948
2926: Put `grouped_values_of` behind a feature gate r=pksunkara a=epage



2948: docs(generate): Move derive example to generate r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-26 20:56:20 +00:00
Ed Page
bfa388420b Put grouped_values_of behind a feature gate
There is enough open work on this, we should probably not have it public
yet, so putting it behind a gate.  See https://github.com/clap-rs/clap/issues/2924
2021-10-26 14:26:50 -05:00
Ed Page
53e10b41e3 fix(derive)!: Error, don't panic!
The derive is generating `Error::raw` (from scratch or by converting
existing erors) and then the inherent `Parser` methods format them.

Fixes #2255
2021-10-26 14:26:50 -05:00
Ed Page
f8bca3a84b fix(error): Never show unrequested color
If the user prints a raw error, it may include color even if the user
turned it off at runtime.  Now we'll be more conservative and never show
color for raw errors.
2021-10-26 14:26:50 -05:00
Ed Page
3c4340c583 feat(error): Allow separate raise, format sites
While `App::error` is what most people will need, `clap_derive` needs to
handle when the site raising the error doesn't have access to the `App`
and needs to defer that to later.
2021-10-26 14:26:50 -05:00
Ed Page
83b074ae92 refactor(error): Extract formatting of raw messages 2021-10-26 14:26:50 -05:00
Ed Page
f1bf9fc250 refactor(error): Delay formatting until the end
This gives us room to add extra context later.
2021-10-26 14:26:50 -05:00
bors[bot]
29972e162a
Merge #2896
2896: docs: Clarify corner caseses with default values r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-25 16:48:17 +00:00
Ed Page
45ef0722f3 docs: Clarify corner caseses with default values
This is meant to lower the chance of confusion with cases like #2714 and #1586.

This is not meant to be exhaustive, looked at the mentioned cases in
that issue and pattern matched on other ones mentioning "is present".
2021-10-23 16:04:10 -05:00
Ed Page
a5ab5f0359 refactor(error): Make 'Error' less churn heavy
When I'm making changes, I frequently have to touch every error
function.  This creates a more standard builder API so we can more
easily add or modify fields without having to update every case.
2021-10-23 16:04:10 -05:00
Ed Page
01055fb796 docs(yaml): Consistently place layout descriptio 2021-10-23 16:04:10 -05:00
Ed Page
cebbb5c40e chore: Silence bad clippy lint
While in some cases "branches-sharing-code" might catch bugs, it overall encourages a form
of DRY that leads to bad code.  In this specific case, it is relying on
the implementation detail of the formatting of each branch being the
same.  If the `'` wasn't part of it, I could see it being about a shared
`?` to go with the shared start of the question.
2021-10-23 10:06:38 -05:00
cherryblossom000
5555416f45
docs: fix affect/effect usage 2021-10-21 19:29:08 +11:00
Ed Page
9f12bfec47 fix!: Rename ArgValue to PossibleValue
In considering potential work for #2683, I realized we might need a type to carry data for
each of the `multiple_values`.  `ArgValue` works both for that and for
possible values, so we need to come up with a better name for one or
both.  Changing `ArgValue`s name now would be ideal since its new in
clap3 and by renaming it, we can reduce churn for users.

While thinking about this, I realized I regularly get these mixed
up, so renaming `ArgValue` to `PossibleValue` I think will help clear
things up, regardless of #2683.
2021-10-19 10:10:37 -05:00
rhysd
e666763acf feat(doc): Fix positions of indices 2021-10-19 16:30:25 +09:00
rhysd
012f318c97 feat(doc): Fix many typos in docs, comments and codes found by typos-cli 2021-10-19 10:38:22 +09:00
Ed Page
e2865c91be perf: Reduce allocations on 'args'
This seems like it'd have close to the same benefits as the suggestion
in the TODO, resolving it.
2021-10-18 16:14:31 -05:00
Ed Page
294cabf7c6 perf: Don't allocate a throw-away Vec 2021-10-18 16:14:31 -05:00
Pavan Kumar Sunkara
585e995811 Release 3.0.0-beta.5 2021-10-17 17:01:18 +01:00
Pavan Kumar Sunkara
e63760e461 Allow possible_values to take string vector reference
Makes it more backward compatible and flexible
2021-10-17 17:01:18 +01:00
Julius Michaelis
16af4f230a cosmetic: spec_vals on separate lines for long help 2021-10-17 22:43:06 +09:00
bors[bot]
1c2b09e57b
Merge #2890
2890: feat: Expose clap-style errors to users r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-17 00:12:07 +00:00
Ed Page
b9cc585997 feat: Expose clap-style errors to users
This gives users the basic error template for quick and dirty messages.
In addition to the lack of customization, they are not given anything to help
them with coloring or for programmayic use (info, source).

This is something I've wanted many times for one-off validation that
can't be expressed with clap's validation or it just wasn't worth
the hoops.  The more pressing need is for #2255, I need `clap_derive`
to be able to create error messages and `Error::with_description` seemed
too disjoint from the rest of the clap experience that it seemed like
users would immediately create issues about it showing up.

With this available, I've gone ahead and deprecated
`Error::with_description` (added in 58512f2fc), assuming this will be
sufficient for users needs (or they can use IO Errors as a back door).
I did so according to the pattern in #2718 despite us not being fully
resolved on that approach yet.
2021-10-16 19:03:17 -05:00
bors[bot]
d78d5a3744
Merge #2899
2899: Allow RegexSet for validator_regex r=epage a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-16 21:40:07 +00:00
Pavan Kumar Sunkara
7dc176ab2a Allow RegexSet for validator_regex 2021-10-16 22:30:52 +01:00
bors[bot]
8647302296
Merge #2718
2718: fix: Ease clap2->clap3 migration with deprecations r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-16 17:52:21 +00:00
bors[bot]
219d59a57a
Merge #2891
2891: refactor: Use USAGE_CODE constant r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-16 01:40:15 +00:00
Ed Page
d3c85773c0 refactor: Use USAGE_CODE constant
I missed a case in #2604.  This will help people discover the
documentation describing why we chose the code we did.
2021-10-15 19:39:00 -05:00
bors[bot]
b835ce9061
Merge #2817
2817: Add support for Multicall executables as subcommands with a Multicall setting r=pksunkara a=fishface60



Co-authored-by: Richard Maw <richard.maw@gmail.com>
2021-10-16 00:32:52 +00:00
Ed Page
81e877c6c2 fix(help): Partial fix for 'help help'
Who knew people need to ask `help` for how to use `help`?

While auditing `MultpleValues`, I saw commented out code.   Looks
its commit (f230cfedc) was part of a large refactor and updating that
part fell through the cracks.  Just simply updating it didn't quite get
it to work.  The advantage of this approach is it gets us closer to how
clap works on its own.

In clap 2.33.3, `cmd help help` looks like
```
myapp-help
Prints this message or the help of the given subcommand(s)

USAGE:
    test-clap help [subcommand]...

ARGS:
    <subcommand>...    The subcommand whose help message to display
```

But clap3 master looks like:
```
myapp

USAGE:
    myapp [SUBCOMMAND]

OPTIONS:
    -h, --help    Print custom help about text

SUBCOMMANDS:
    help      Print this message or the help of the given subcommand(s)
    subcmd
```

This change improves it to:
```
myapp-help

Print this message or the help of the given subcommand(s)

USAGE:
    myapp help [SUBCOMMAND]...

ARGS:
    <SUBCOMMAND>...    The subcommand whose help message to display

OPTIONS:
    -h, --help    Print custom help about text
```

We still have global arguments showing up (like `-h`) that will error but its
an improvement!  In general, I'd like to find a way to leverage clap's stanard
behavior for implementing this so we don't have to worry about any of these
corner cases in the future.

Note: compared to clap2, I changed `<subcommand>` to `<SUBCOMMAND>` because I
believe the standard convention is for value names to be all caps (e.g.
`clap_derive` has been updated to default to that).
2021-10-15 18:24:15 -05:00
Richard Maw
b92f2c0339 fixup! formatting lint 2021-10-15 21:14:26 +01:00
Ed Page
a43da7ca61 fix: Ease clap2->clap3 migration with deprecations
- `App::with_defaults` was not included since that has been deprecated
  since 2.14
- `App::args_from_usage` does not have a close enough parallel in the
  new API, as far as I could tell
- `ArgMatches::usage` cannot have a thin wrapper around
  `App::generate_usage`.
- `App::write_*`: getting lazy, didn't seem like high value functions
- Any `Settings` (some things need to be figured out here)

This is a part of #2617
2021-10-15 14:19:16 -05:00
bors[bot]
f9208ae4e3
Merge #2886
2886: docs: Encourage multiple_occurrences r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 17:57:07 +00:00
Ed Page
59497629e8 docs: Encourage multiple_occurrences
There were fewer occasions than I expected where the use of
`multiple_values` was superfluous and we could instead use the more
predictable `multiple_occurrences`.

In terms of the remaining `multiple` split work, #1772 will take care of the derive
behavior and #2692 will resolve any remaining issues with values vs
occurrences in positional arguments.

Fixes #2816
2021-10-15 11:41:40 -05:00
Ed Page
6ee5fc4d5d fix(app): Rename generaet_usage to render_usage
This is inline with all of our other help-related functions that return
strings.

This is a part of #2164

BREAKING CHANEG: `App::generate_usage` (added in v3) ->
`App::render_usage`.
2021-10-15 09:36:44 -05:00
Ed Page
7f05c15a5e fix: Give Arg::help_heading priority over App::help_heading
PR #1211 originally added `help_heading` with the current priority
(`App::help_heading` wins).

In #1958, the author had proposed to change this

> Note that I made the existing arg's heading a priority over the one in App::help_heading

This was reverted on reviewer request because

> Thanks for the priority explanation. Yes, please make the app's help
> heading a priority. I can see how it would be useful when people might
> want to reuse args.

Re-using args is an important use case but this makes life difficult
for anyone using `help_heading` with `clap_derive` because the user
can only call `App::help_heading` once per struct.  Derive users can't get
per-field granularity with `App::help_heading` like the builder API.

As a bonus, I think this will be the least surpising to users.  Users
generally expect the more generic specification (App) to be overridden by the
more specific specification (Arg).  Honestly, I had thought this PR is
how `help_heading` worked  until I dug into the code with #2872.

In the argument re-use cases, a workaround is for the reusable arguments
to **not** set their help_heading and require the caller to set it as
needed.

Fixes #2873
2021-10-14 18:23:10 -05:00
bors[bot]
11453065c5
Merge #2871 #2872 #2876
2871: Better positional checks r=epage a=pksunkara



2872: Iterate on help_heading to prepare for derive support r=pksunkara a=epage



2876: Generate/bash: add possible_values to completion when available r=pksunkara a=nstinus



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
Co-authored-by: Ed Page <eopage@gmail.com>
Co-authored-by: Nicolas Stinus <nstinus@latourtrading.com>
2021-10-14 20:23:54 +00:00
Ed Page
072d038d8f fix: Apply app help heading in App::args()
We aren't setting it when bulk-adding arguments.
2021-10-14 13:23:36 -05:00
Ed Page
9ee7fa2b01 feat(yaml): Implement help_heading support
Now that `help_heading`'s API is loosened with an `Into<Option>`, we can
more easily allow the existing yaml functionality to work.  This still
misses the ability to set the help heading to nothing.

This reverts commit 9031deb806.
2021-10-14 11:52:30 -05:00
Ed Page
ad3c5bcfb8 feat: Make it more natural to set heading
This makes `Some()` optional.  This change was made with the derive API
in mind where you are unlikely to clear directly but we still need the
ability to clear.
2021-10-14 11:52:15 -05:00
Ed Page
5bbcc0f4ba feat(app): Introspect current help heading
This will help for #2803 so we can capture and restore the help heading
around flattened derives.
2021-10-14 11:43:27 -05:00
Ed Page
a570976d92 fix(app): Make App and Arg help_heading consistent
In part, this is just fixing a papercut where someone will try to use
the API in the same way between the two but it fails and they'll have to
consult the docs / rust-analyzer.

The bigger reason is that this is more derive-friendly for dealing with #2803
since we will be able to just ask for the current help heading
before running the app and then restore it back, rather than having to
conditionalize the revert logic.
2021-10-14 11:39:51 -05:00
Ed Page
9031deb806 fix: Remove help_heading from YAML
Problems with this
- It is incompatible with the new signature planned for
  `App::help_heading`
- It is missing from `Arg` which is where this is more needed
- All this can do is set a global help heading because you can duplicate
  keys (`clap_derive` has a similar problem but it at least has `flatten`)
2021-10-14 11:39:51 -05:00
Pavan Kumar Sunkara
f371cfed29 fix: Better positional checks 2021-10-14 09:26:53 +01:00
Pavan Kumar Sunkara
2454dabc03 refactor: Remove get_flags API 2021-10-14 09:26:09 +01:00
Ed Page
61c9e6265b fix(help)!: Merge OPTIONS / FLAGS default groups
For those that want the original behavior, you can usxe
`arg.help_heading(Some("FLAGS"))` on your flags.  Limitations:
- This will not give you a special sort order
- This will not get a `[FLAGS]` added to usage

For templates, we removed `{unified}` and `{flags}`.  To help people
catch these, a debug_assert was added.

I'm unsure but I think there might be a change in behavior in calcuating
when to show `[OPTION]` in usage.  The old code only looked at
`required` while flags looked only at arg groups.  We now look at both.

Ideally we'd add these in `_build` and remove special casing for
no-groups except in the sort order of groups.  I feel like thats best
left for later.

This also reduced the scope of `App`s public API.
`get_*_with_no_heading` seemed a bit specialized to be in the public
API.  #2853 looks at splitting it out into its own PR.

BREAKING CHANGE: Multiple
- `UnifiedHelpMessage` removed
- `{flags}` and `{unified}` are removed and will assert when present.
- `get_*_with_no_heading` removed

Fixes #2807
2021-10-13 11:42:10 -05:00
Pavan Kumar Sunkara
efeb02cd34 fix!: Make color settings an enum 2021-10-13 13:54:44 +01:00
Pavan Kumar Sunkara
d46fd26c12 chore: Rename App::color to App::get_color 2021-10-13 02:20:04 +01:00
bors[bot]
d833d667df
Merge #2863
2863: fix(gen): Ensure subcommands are post-processed r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 21:23:54 +00:00
Ed Page
a61b60816c fix(gen): Ensure subcommands are post-processed
`App::get_matches` lazily post-processes `App`s and `Arg`s so we don't
do it to subcommands that are never run (downside being people have to
exercise their full app to get debug_asserts).

`clap_generate` was only post-processing the top-level `App` and `Arg`s,
ignoring the sub-commands.  In #2858, we noticed that `--version` was
being left in the completions instead of being removed during the
`_build` step.  We would also have an incorrect `num_vals` and a host of
other problems.

This change adds a `App::_build_all` function for `clap_generate` to use
to eagerly build everything.  By having it there, we make sure
everywhere that needs eager building, gets it (like some tests).

In `clap_generate::utils`, we add a unit test to ensure the subcommand's
`--version` was removed.

For some other tests specifying `.version()`, I added
`AppSettings::PropagateVersion` to make it behave more consistently.
The places I didn't were generally where the version was conditionally
set.

For `clap_generate/tests/generate_completions.rs`, I had to adjust the
`conflicts_with` because the subcommand was inheriting the argument with
it defined *but* the subcommand did not have the argument, tripping up a
debug assert.

Fixes #2860
2021-10-12 15:54:26 -05:00
Richard Maw
b2180e9d72 fixup! Gate Multicall behind unstable feature 2021-10-12 20:35:59 +01:00
Ed Page
f48261a2a2 Partial Revert of "Change MissingArgumentOrSubcommand to DisplayHelpOnMissingArgumentOrSubcommand and don't use stderr"
This partially reverts commit 7f627fc.

This reverts the error code change but not the `ErrorKind` change.  I
was mixed on whether we should do that or not.  The benefit is it makes
it so people can check the Kind for cases like #2021.  On the other
hand, it doesn't seem that hard to re-implement the feature.

Fixes #2767
2021-10-12 14:09:08 -05:00
Paul Seyfert
25e337adb1 [clap_generate] [zsh] sort out multiple occurrence vs multiple_value. 2021-10-12 10:48:37 +01:00
bors[bot]
6d046c7aac
Merge #2848
2848: fix: Deprecate Macro API r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 07:36:50 +00:00
bors[bot]
a67aea232d
Merge #2852
2852: fix(help): Show [OPTIONS] with help_heading r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 00:55:16 +00:00
Ed Page
350ab9daf7 fix(help): Show [OPTIONS] with help_heading
This was changed in #1989 without an explanation:
- In the help template, there isn't a way to expose with help_headings,
  so show all.
- In usage, we don't know whether the user wants to see `[FLAGS]` /
  `[OPTIONS]` or not, so let's default to showing them.
2021-10-11 19:13:53 -05:00
Richard Maw
971b6b683e fixup! Move explanatory text from examples to docstring 2021-10-11 22:08:51 +01:00
Ed Page
0a53fafddf fix: Deprecate Macro API
Fixes #2835
2021-10-11 15:06:38 -05:00
Richard Maw
f14db03eec Add Multicall setting
If the AppSettings::Multicall setting is given
then argv0 is parsed as the first subcommand argument
or parsed as normal with any other name.
2021-10-11 20:00:24 +01:00
Ed Page
35d53d9dcf feat(generate): 'impl ArgEnum for Shell'
These keeps `FromStr` for ease of use with `value_of_t`.

This includes adding test to make sure everything works as expected.
2021-10-11 10:44:48 -05:00
bors[bot]
562e64c723
Merge #2845
2845: fix(help)!: Consoldiate color settings r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-11 14:17:10 +00:00
Ed Page
6dd9d467ce fix(help)!: Consoldiate color settings
A lot of users expected `color` feature flag and `ColorAuto` etc to
control all colors.  Having this extra flag around is easy to miss and
adds to our overall settings bloat, making it harder to find settings
people want.

This completely removes it, rather than make it deprecated like
functions in #2617, because there is extra work to mark things
deprecated as Settings and we should decide on our strategy first before
investing time in addressing that issue.

Fixes #2806
2021-10-11 09:01:13 -05:00
Waleed Khan
e73ec0887d add App::get_long_about 2021-10-10 17:17:55 -07:00
Ed Page
d840d5650e fix(derive)!: Rename Clap to Parser.
Before #2005, `Clap` was a special trait that derived all clap traits it
detected were relevant (including an enum getting both `ArgEnum`,
`Clap`, and `Subcommand`).  Now, we have elevated `Clap`, `Args`,
`Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't
very descriptive.

This also helps further clarify the relationships so a crate providing
an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely
to choose the needed trait to derive.

Also, my proposed fix fo #2785 includes making `App` attributes almost
exclusively for `Clap`.  Clarifying the names/roles will help
communicate this.

For prior discussion, see #2583
2021-10-09 20:12:03 -05:00
bors[bot]
e8ec11e57f
Merge #2837
2837: fix: Gate App::replace r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-09 16:27:41 +00:00
Ed Page
dfbeb71077 fix: Gate App::replace
We are concerned about the level of polish of this feature and are
unsure enough about its future, we've decided to gate it to unblock the
v3 release.
2021-10-09 10:49:10 -05:00
Kevin K
7b45695878
breaking(DisableVersionForSubcommands): removed
This commit removes `AppSettings::DisableVersionForSubcommand` as it's
now a moot setting with clap's default functionality of not building a
version flag unless there actually exists version information.

`clap_up` must still be changed to remove this variant instead of the
current configuration to simply rename the variant.
2021-10-09 11:12:50 -04:00
Kevin K
9fbe5841a7
chore: clippy lint fixes 2021-10-09 11:12:50 -04:00
Kevin K
bb26ed1c8b
imp: adds debug_asserts against generating meaningless flags
This commit adds several debug asserts that ensure the user has not
accidentally generated a version flag that has no information. The
exception to this case is when the user wants to generate a version
flag, but then handle the version display manually. I.e. one can still
generate a "meaningless" version flag, but use
`AppSettings::NoAutoVersion` which is allowed.
2021-10-09 11:12:50 -04:00
Kevin K
07aae5ac54
docs(AppSettings): documents NoAutoHelp and NoAutoVersion
Since these tie in closely with the new default behavior of not
auto-generating the `-V/--version` flags when no information has been provided they are now documented.
2021-10-09 11:12:50 -04:00
Kevin K
14c8850019
tests: fixes test to new default behavior
This commit corrects tests to not expect the `-V,--version` flag when no
version information has been provided.
2021-10-09 11:12:50 -04:00
Kevin K
7169c47fed
imp(version flag): no longer generates a version unconditionally
This commit changes the default behavior of clap to no longer generate a
`-V, --version` flag when no version information has been provided.

Version information can be provided via `App::version`,
`App::long_version`, or via `App::mut_arg("version", |_| ..)`. Using any
of the above is the only way to have clap auto-generate the version flag.

Technically, clap still generates a version flag, however it is removed
prior to parsing if the user has not provided any version information
via one of the mentioned methods.

Relates to [#2812](https://github.com/clap-rs/clap/issues/2812)
2021-10-09 11:06:48 -04:00
Ed Page
56a6a7418e fix: Allow unicode-aware case insensitivity with ArgValue
This also opens us up to being more unicode aware in other places, like
our sorting of arguments in the help.

Fixes #2792
2021-10-09 07:21:45 -05:00
Ed Page
7b5a4c9c2d feat: Add backtraces to errors
This is gated behind the `debug` feature flag so only explicit debugging
cases pay the build time and runtime costs.

The builder API's stack traces are generally not too interesting.  Where
this really helps is with `clap_derive`.  We currently panic on
unexpected conditions which at least gives us a backtrace.  We'd like to
turn these into errors but to do so would lose those debuggin
backtraces, which is where this comes in.

This is a part of #2255
2021-10-07 10:02:34 -05:00
Ed Page
62eff1f8d3
Merge pull request #2804 from epage/multiple
fix(parser): Allow multiple_occurrecnes with positional args
2021-10-04 13:57:33 -05:00
Ed Page
8e780e364d fix(parser): Allow multiple_occurrecnes with positional args
This unblocks
- Defining repeated tuples in positional arguments
- Potentially using this in #1772

Fixes #2784
2021-10-04 12:09:54 -05:00
patrick-gu
edd0124af0
Fix disabling the default help and version subcommands/flags (#2796)
* Check for `DisableHelpFlag` along with `NoAutoHelp`

Also applies for `DisableHelpSubcommand` and `DisableVersionFlag` with `NoAutoVersion`

* Add tests for overriding help and version, and disabling version.

These override by disabling the default and adding a new one.

* Don't use `default_missing_value` for `override_version_using_short`

* Check errors by the API.

This changes the `disabled_version_long` and `disabled_version_short` tests.

This is opposed to comparing the stderr output.
2021-10-04 15:01:09 +01:00
ModProg
08e8c53862 refactor(ArgEnum): replace unwrap with except, arg_value -> to_arg_value 2021-10-01 16:14:10 +02:00
Ed Page
3b2e3ffddf
Merge pull request #2762 from ModProg/ArgValue-derive
ArgValue derive
2021-10-01 08:43:40 -05:00
ModProg
47ff3ed945 documentation for ArgValue 2021-09-29 20:55:47 +02:00
ModProg
480035ac9c ArgEnum: Slice instead of array, from_str in ArgEnum implemented 2021-09-29 18:33:43 +02:00
Pavan Kumar Sunkara
5940bb2360
Merge pull request #2794 from ldm0/simplify
Less format & branch
2021-09-28 22:21:09 +01:00
ModProg
ac1a9d6d13 address epage's remarks 2021-09-27 22:06:17 +02:00
liudingming
3206db99af less format macro, less branches. 2021-09-27 23:34:13 +08:00
ModProg
76f7211d8b small changes 2021-09-27 01:29:10 +02:00
ModProg
f002cdcc99 move alias implementation to ArgValue for derive 2021-09-27 01:18:47 +02:00
ModProg
d3f0534939 add hidden aliases to ArgValue 2021-09-26 22:46:23 +02:00
liudingming
7ba46400e4 Resolve a todo 2021-09-27 02:03:28 +08:00
Roland Fredenhagen
88d7d02555 Working Implementation 2021-09-26 16:32:46 +02:00
ModProg
b589a6ce06 feat(derive:arg_enum): use ArgValue in ArgEnum trait 2021-09-26 16:32:46 +02:00
Pavan Kumar Sunkara
699a3f76d6 Implement BitOr for settings 2021-09-23 14:57:10 +05:30
Roland Fredenhagen
5580e8c465
ArgValue builder (#2758)
* feat(arg_value): ArgValue can be used for possible_values

Through the ArgValue it is possible:

* `hide` possible_values from showing in completion, help and validation
* add `about` to possible_values in completion

* Resolved a few change-requests by epage

* make clippy happy

* add ArgValue::get_visible_value

* remove verbose destructering

* rename ArgValue::get_hidden to ArgValue::is_hidden

* add test for help output of hidden ArgValues

* Documentation for ArgValue

There is an issue that required to implement From<&ArgValue> for
ArgValue. We should probably find a solution without that.

* fix requested changes by epage

* fix formatting

* add deref in possible_values call to remove From<&&str>

* make clippy happy

* use copied() instad of map(|v|*v)

* Finishing up for merge, hopefully

* changes requested by pksunkara
2021-09-19 10:29:09 +00:00
patrick-gu
90dde89ec4 Apply value_delimiter to default values 2021-09-18 15:15:25 -07:00
Ed Page
b3847b76c4 refactor: Remove vec_map dependency
Doesn't look like this dependency is buying us anything at this point,
so removing it.
2021-09-17 15:14:49 -05:00
Pavan Kumar Sunkara
76859b16bb
Merge pull request #2773 from tangmi/fix-large-display-order
Add test for very large display_order values and a possible fix
2021-09-17 19:39:37 +01:00
Mustafa Guler
50b9e65d39 Fix bug with duplicate error messages
This addresses a bug that causes duplicate flags reported in user-facing
error messages when two flags require one-another but also are required
under other conditions. The fix involves removing duplicates in unrolled
requirements, which addresses the user-facing aspect of this bug.
2021-09-17 10:47:06 -04:00
Michael Tang
cc592ed800 Add test for very large display_order values and a possible fix.
Fixes #2772
2021-09-16 19:11:30 -07:00
patrick-gu
044f9c5669
Don't suggest help or --help when not applicable (#2749)
* Don't suggest `help` or `--help` when not applicable

* Apply suggestions from code review

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>

* Update test usage to match intended

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-09-04 20:10:24 +00:00
dylni
6311c894cc Fix compile errors 2021-08-29 10:24:56 -04:00
dylni
a50591b16b Fix warnings 2021-08-29 10:10:26 -04:00
dylni
dc65513966 Replace ArgStr with os_str_bytes::RawOsStr 2021-08-29 10:00:30 -04:00
liudingming
898894cf35 Make clap::Error Send and Sync again 2021-08-29 17:21:08 +08:00
liudingming
f200828045 Add regression test 2021-08-29 17:21:08 +08:00
Pavan Kumar Sunkara
f085fa64f4
Merge pull request #2722 from epage/group
fix(yaml): Don't panic on multiple groups
2021-08-19 07:40:41 +01:00
Ed Page
bd25b5f615 fix(yaml): Don't panic on multiple groups
Because we gradually build the `ArgGroup` as we parse the YAML, we don't
use `ArgGroup::new`.  Clap3 introduced an internal `id` in addition to
the public `name` and it appears that this custom initialization code
was not updated.

This shows the problem with publically exposing `impl Default`.
Choices:
- Remove `impl Default`
  - Always valid
  - Requires spreading invariants
  - Callers can't implement code the same way we do
- Add `ArgGroup::name`
  - Can be constructed in an invalid state
  - Centralizes invariants
  - A caller could implement code like the yaml logic

I decided to go with `ArgGroup::name`.

Fixes #2719
2021-08-18 15:16:44 -05:00
Ed Page
aeaf01e3e7 fix: Provide path to avoid UTF-8 panics
Before, validating UTF-8 was all-or-nothing and would cause a `panic` if
someone used the right API with non-UTF-8 input.

Now, all arguments are validated for UTF-8, unless opted-out.  This
ensures a non-panicing path forward at the cost of people using the
builder API that previously did `value_of_os` need to now set this flag.

Fixes #751
2021-08-18 14:15:18 -05:00
Ed Page
329fe4a24b fix: Swallow broken pipes
Previously, we paniced.  This is one less reason people have to call
lower level `get_matches` to get the commonly expected behavior, making
it more likely for the Rust community to "do the right thing"

Fixes #2659
2021-08-18 10:16:57 -05:00
Donough Liu
0394ae6102
Fix handling of number_of_values when displaying arg (#2701)
* Remove dead logic

* Outline common logic

* Fix issue 1571
2021-08-17 09:17:18 +00:00
Pavan Kumar Sunkara
9d5cf64d6a
Merge pull request #2704 from jrheard/patch-1
fix typo
2021-08-16 10:45:33 +01:00
JR Heard
465d495b6d
fix typo 2021-08-15 20:02:18 -07:00
Pavan Kumar Sunkara
9dd75987df Remove TakesValue restriction for HideEnv* 2021-08-15 19:40:24 +01:00
Pavan Kumar Sunkara
52be134949 Release 3.0.0-beta.4
clap@3.0.0-beta.4
clap_derive@3.0.0-beta.4
clap_generate@3.0.0-beta.4

Generated by cargo-workspaces
2021-08-14 23:40:49 +01:00
Pavan Kumar Sunkara
73b28fb104 Release 3.0.0-beta.3
clap@3.0.0-beta.3
clap_derive@3.0.0-beta.3
clap_generate@3.0.0-beta.3

Generated by cargo-workspaces
2021-08-14 23:01:13 +01:00
Pavan Kumar Sunkara
a9b86ecefc Update changelog 2021-08-14 22:46:49 +01:00
TheDaemoness
f411a65d82
Fix invalid_value returning an Error with no info 2021-08-14 11:28:51 -07:00
Pavan Kumar Sunkara
203613d5e3
Merge pull request #2696 from ldm0/override
Make `overrides_with` working when `MultipleValues` is enabled.
2021-08-14 10:41:40 +01:00
liudingming
a85857dfb0 Make overrides_with working when MultipleValues is enabled. 2021-08-14 16:34:26 +08:00
Pavan Kumar Sunkara
441ff68c2d
Merge pull request #2694 from clap-rs/env-feature
Add env feature gate
2021-08-14 03:11:21 +01:00
Pavan Kumar Sunkara
c7985fb73e Add env feature gate 2021-08-14 01:55:05 +01:00
Pavan Kumar Sunkara
61eb921f63 Fix value_names & num_vals interaction 2021-08-14 01:08:44 +01:00
Ed Page
2eb22e2b36 fix!: value_name/value_names should not append
Instead they should behave like `default_value`/`default_values`.

In implementingt this, I didn't see any reason to be using a `VecMap`.
In fact, this helped simplify the code / make intent clearer.

With this, we are also able to simplify the derive macro work from #2633.

Fixes #2634

BREAKING CHANGE: `value_name`/`value_names` always overwrite, rather
than append.  We expect the impact to be minimal.
2021-08-13 15:37:03 -05:00
Pavan Kumar Sunkara
24bfd2b92c Fix test errors 2021-08-13 20:58:38 +01:00
Pavan Kumar Sunkara
d64ced0311
Merge pull request #2686 from ldm0/delimiter
Make `value_delimiter` accept `char` rather than `String`
2021-08-13 20:53:21 +01:00
liudingming
a60836d96a Make value_delimiter accept char rather than String 2021-08-14 02:54:56 +08:00
liudingming
a8060d305b Tweaks ArgsNegateSubcommands's doc 2021-08-14 02:30:27 +08:00
Pavan Kumar Sunkara
476dd190b7
Merge pull request #2682 from clap-rs/checker
Set TakesValue to true for positional args when building
2021-08-12 22:46:15 +01:00
Pavan Kumar Sunkara
8f2ba607aa
Merge pull request #2534 from stevenengler/hide-heading
Hide help heading when all args are hidden
2021-08-12 21:32:07 +01:00
Pavan Kumar Sunkara
b4a662b6c9 Set TakesValue to true for positional args when building 2021-08-12 21:27:42 +01:00
Steven Engler
1bd63feffe Hide help heading when all args are hidden 2021-08-12 00:51:58 +01:00
Pavan Kumar Sunkara
6ae15a79b6 Remove settings that are inherently global 2021-08-11 22:41:25 +01:00
rami3l
5a965caf1e feat(parser): accept non-false literals with env vars as true, take 2 2021-08-10 19:13:43 +02:00
rami3l
5f781c72a5 feat(parser): accept non-false literals with env vars as true 2021-08-10 12:21:12 +02:00
rami3l
d32b6bf764 fix(test): fix doc test 2021-08-10 12:21:12 +02:00
rami3l
f2f9b665ed feat(parser): accept boolean literal with env vars, take 1 2021-08-10 12:21:02 +02:00
liudingming
696f93c4f5 Fix some work on ArgStr 2021-08-09 04:26:01 +08:00
liudingming
5f70e38c2a Optimize ArgStr 2021-08-09 02:22:31 +08:00
liudingming
216aab2479 Remove TrailingValues from app settings 2021-08-08 03:41:23 +08:00
liudingming
963aa1977d Remove ValidArgFound from app settings 2021-08-08 03:41:23 +08:00
liudingming
e851a82080 Move pos_counter before parsing flags.
Then checking if AllowHyphenValues is set when parsing flag is possible.
2021-08-08 03:38:41 +08:00
liudingming
b88d933d96 Extract erroring from parsing.
Rename needs_valueof to parse_result

Use ParseResult more

Less predicting, more fallback

Remove non-sense ParsingResult::NotFound

Merge FlagSubCommand and FlagSubCommandShort

Merge NoMatchingLongArg and NoMatchingShortArg

Better documentation for pos_counter bumping

Denoise of pos_counter

Split ParseState from ParseResult

Remove ParseResult::Flag

small cleanup
2021-08-08 03:38:40 +08:00
liudingming
82d25401a0 Move logic out 2021-08-08 03:34:10 +08:00
liudingming
ca8623c774 Remove duplicate empty value checker 2021-08-08 03:34:10 +08:00
liudingming
d2fec9128f fmt::write -> push_str 2021-08-08 00:25:51 +08:00
rami3l
adc34a2680 fix(style): eliminate several clippy warnings 2021-08-02 22:31:59 +02:00
Pavan Kumar Sunkara
4bec66dd03
Merge pull request #2619 from rami3l/flag-literal
fix(parser): Ban long flags with literals
2021-08-01 12:31:29 +01:00
rami3l
7f8f5ccc9a Revert "fix(style): fix code format warning"
This reverts commit a4a4d4c307.
2021-08-01 11:41:29 +02:00
Abyss
faa25f9e67 Make colorizer respect ColorChoice::Always 2021-07-31 18:12:54 -04:00
liudingming
ab119b342a Fix value_of returns None when the first value group is empty 2021-08-01 03:56:23 +08:00
patrick-gu
88dec14775
Fix order of arguments in help message with AllowMissingPositional (#2648)
* Fix small formatting error

I accidentally introduced this in #2642

* Fix order of arguments in help message with AllowMissingPositional
2021-07-31 07:39:23 +01:00
Pavan Kumar Sunkara
ff95eb2f5b
Merge pull request #2647 from clap-rs/msrv
Bump msrv to 1.54.0
2021-07-31 05:45:02 +01:00
Pavan Kumar Sunkara
619f4c153c Fix format 2021-07-30 23:01:05 +01:00
Pavan Kumar Sunkara
6994be4f15 Remove doc feature 2021-07-30 22:49:11 +01:00
rami3l
a4a4d4c307 fix(style): fix code format warning 2021-07-30 22:33:56 +02:00
rami3l
29e3dc2c47 fix(parser): run check_for_help_and_version_str only if no literal is found with flag 2021-07-30 22:33:56 +02:00
rami3l
87479dfb8c fix: ban all uses of literals with flags 2021-07-30 22:33:56 +02:00
rami3l
2d2db652ef fix: fix #1649, take 1 2021-07-30 22:33:56 +02:00
Ed Page
241d183b9c Bump MSRV to 1.54.0
- This makes it so `doc` compiles on stable

Fixes #2618
2021-07-30 10:19:21 +01:00
liudingming
a419f25fdb Fix issue, add tests 2021-07-30 15:39:34 +08:00
liudingming
3791f7e5ad Fix long_arg 2021-07-30 15:39:34 +08:00
liudingming
5ab16f7199 Improve parse_long_arg 2021-07-30 15:39:34 +08:00
liudingming
e8838e1794 fix clippy 2021-07-30 15:39:34 +08:00
liudingming
9509372f12 Improve parse_opt 2021-07-30 15:39:34 +08:00
Pavan Kumar Sunkara
6ea223bc6e
Merge pull request #2644 from ldm0/clippy
Fix clippy
2021-07-30 08:38:34 +01:00
liudingming
44b7eee404 Fix clippy 2021-07-30 13:36:38 +08:00
patrick-gu
a4dc72ed19 Replace "Prints" with "Print" for default help and version commands 2021-07-29 20:23:25 -07:00
Ed Page
6a70c744e0 fix(derive): Allow partial update of flattened Subcommand arguments
When using `#[clap(flatten)]` inside of a `Subcommand`, we would do a
`from` instead of an `update`.

The challenge is knowing when we are
going into a flattened subcommand vs changing the variant.  To resolve
this, I added a `Subcommand:has_subcommand(name)` trait method that we
generate, so we can ask.
2021-07-27 12:14:53 -05:00
Pavan Kumar Sunkara
5fbd764b06
Merge pull request #2622 from patrick-gu/master
Refactor creation of `App` and `Arg` from YAML
2021-07-27 10:31:55 +01:00
Ed Page
d643fb3c32 feat(derive): Make it possible to use ArgEnum with default_value
This doesn't solve the problem end-to-end but at least makes it possible
to solve by the user and improve in the future.
2021-07-26 10:33:14 -05:00
patrick-gu
9b64ac2b45 Refactor creation of App and Arg from YAML
Improved the `impl`s of `From` for `&'help Yaml` to use expects with useful messages instead of unwraps. Also made changes to avoid potentially fetching redundant data from YAML hashes and unwrapping the same data multiple times. Finally, there are tests to ensure the panics are correct.
2021-07-25 15:24:43 -07:00
Pavan Kumar Sunkara
79e3b37ecc
Merge pull request #2604 from epage/exit
fix(exit): Be consistent in exit code
2021-07-25 14:32:47 +01:00
Pavan Kumar Sunkara
27311139c2
Merge pull request #2610 from ldm0/value_name
Print `value_name` `number_of_values` times with single value_name
2021-07-25 14:23:21 +01:00
liudingming
62fa1e7454 Print value_name number_of_values times with single value_name 2021-07-21 03:38:58 +08:00
liudingming
6094520541 Don't show default_val in smart usage 2021-07-21 02:50:41 +08:00
Ed Page
6e24c849fb fix(exit): Be consistent in exit code
PR #1637 switched clap to report `64` on errors and then #1653 switch it
to `2`, but both missed a case.  This also documents the reason why inline
since I had to go and dig through the history to re-discover the
motivation.
2021-07-19 11:21:01 -05:00
hosseind88
cc2e07ea61 Remove a redundant word in AppSettings::NoBinaryName enum explanation 2021-07-19 17:56:57 +04:30
Ed Page
7f08773a5a fix(derive)!: Compile-error on nested subcommands
Before, partial command lines would panic at runtime.  Now it'll be a
compile error

For example:
```
pub enum Opt {
  Daemon(DaemonCommand),
}

pub enum DaemonCommand {
  Start,
  Stop,
}
```

Gives:
```
error[E0277]: the trait bound `DaemonCommand: clap::Args` is not satisfied
   --> clap_derive/tests/subcommands.rs:297:16
    |
297 |         Daemon(DaemonCommand),
    |                ^^^^^^^^^^^^^ the trait `clap::Args` is not implemented for `DaemonCommand`
    |
    = note: required by `augment_args`
```

To nest this, you currently need `enum -> struct -> enum`.  A later
change will make it so you can use the `subcommand` attribute within
enums to cover this case.

This is a part of #2005
2021-07-15 11:45:13 -05:00
Pavan Kumar Sunkara
894be6799c
Merge pull request #2585 from epage/argenum
fix(derive): `Clap` should not derive `ArgEnum`
2021-07-14 18:01:31 +01:00
Ed Page
6cc76e7237 fix(derive): Clap should not derive ArgEnum
While having convinience derives can be helpful, deriving traits that
are not used in similar situations (`Clap` and `ArgEnum`) can make
things harder
- From a user, derives are opaque and create uncertainty on how to use
  the API if not kept crystal clear (deriving a name gives you the trait
  by that name)
- This makes documentation harder to write and read
- You can use types in unintended places, which is made worse for crate
  APIs because changing this breaks compatibility.

Fixes #2584
2021-07-14 10:50:26 -05:00
Pavan Kumar Sunkara
af6f7af368
Merge pull request #2577 from tshepang/fix-links
fix remaining intra-doc links
2021-07-13 00:43:28 +01:00
Ed Page
3be79b9e1b
docs(derive): Update trait doc-comments (#2579)
* docs(derive): Update trait doc-comments

* Apply suggestions from code review

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-07-12 21:43:03 +01:00
codedust
15d49064c3
Fix grammar in require_delimiter fn docs 2021-07-11 12:19:54 +02:00
Tshepang Lekhonkhobe
b4eddf158d fix remaining intra-doc links 2021-07-10 21:00:34 +02:00
Tshepang Lekhonkhobe
f5758034f0 fix a bunch of intra-doc links 2021-07-03 23:59:46 +02:00
anatawa12
89d1519f69
Show summary in subcommands list (#2558)
* Show short about in SUBCOMMANDS list

* add tests

* move test

* cargo fmt
2021-06-20 16:28:50 +01:00
Ethan Budd
6a48698fcd
Add a new arg option for the max_occurrences (#2543)
* add a new arg option for the max_occurrences

* check ErrorKind in tests

* Updated grammer in doc comments

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>

* assert is_err() before unwraping

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-06-17 19:54:24 +01:00
Pavan Kumar Sunkara
373ded784c Fix clippy lint 2021-06-17 19:19:56 +01:00
Rémi Lauzier
c4f534228b
Fix some nightly clippy warnings 2021-06-16 23:25:13 -04:00
Pavan Kumar Sunkara
947523f7f5
Merge pull request #2480 from kolloch/feature/partial-parsing
setting: IgnoreErrors - Allow parsing despite missing option values
2021-06-16 09:09:52 +01:00
Pavan Kumar Sunkara
e5e20b389e Forbid multiple_occurrences for positional args 2021-06-16 08:27:04 +01:00
Pavan Kumar Sunkara
3f94d17c71 Removed Arg::multiple 2021-06-16 07:17:11 +01:00
Pavan Kumar Sunkara
43909ddefc Fix some docs for app settings 2021-06-16 02:54:49 +01:00
Peter Kolloch
171dcbe424 setting: IgnoreErrors - Reaction to review comments
https://github.com/clap-rs/clap/pull/2480
2021-06-14 10:26:23 +02:00
Peter Kolloch
b0310e2d6e settings: IgnoreErrors - prefix debug statements with fn name 2021-06-14 10:26:23 +02:00
Peter Kolloch
c50d338962 setting: IgnoreErrors - Allow parsing despite missing option values
Implemented as AppSetting::Ignore errors as suggested by
@CreepySkeleton in
https://github.com/clap-rs/clap/issues/1880#issuecomment-637779787.

This is not a complete implementation but it works already in
surprisingly many situations.

https://github.com/clap-rs/clap/issues/1880
2021-06-14 10:26:18 +02:00
Tshepang Lekhonkhobe
e3bfa50e8f
docs: fix links to Subcommand (#2518)
* docs: fix links to Subcommand

These were broken by 03333800fe

* docs: remove crate links from body content

Addresses code review

* docs: allow some room to breath

Addresses code review
2021-06-07 11:19:45 +01:00
rami3l
6e158d9f8d
refactor(validator): cleanup code (#2512)
* refactor(validator): use filtermap style for `gather_conflicts` and `validate_exclusive`

* refactor(validator): remove nested `filter`s in `build_conflict_err_usage`

* refactor(validator): add more code beautifying

* refactor(validator): revert some unnecessary changes

* refactor(validator): revert some unnecessary changes, take 2
2021-06-07 00:45:45 +01:00
Terts Diepraam
6a574bf73c
Fix documentation for InferLongArgs
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-06-06 12:32:32 +02:00
Terts Diepraam
834f600a6f infer long arguments 2021-06-05 13:18:06 +02:00
Pavan Kumar Sunkara
82e42cd07e Ignore extra fields in YAML only when specified 2021-06-01 21:59:44 +01:00
rami3l
a91ca7fc1b refactor(parser): encode all parsing state of FlagSubCommand in Parser 2021-05-29 21:26:21 +02:00
rami3l
65b3892ef6
docs: add more explanation to #2501 fix (#2507)
* fix(parser): replace `unwrap` with `expect`

* docs(parser): add more comments explaining `done_short_args`

* docs(parser): add more comments explaining `keep_state`
2021-05-28 21:51:00 +01:00
rami3l
fbd338ce26
fix: flag_subcommands unexpected behavior after long arg (#2501)
* fix(wip): add necessary debugging prints for analysis

* fix(wip): implement the fix, take 1

* docs: add docstring for `Parser::flag_subcmd_at` and `Parser::flag_subcmd_skip`

* test: make `flag_subcommand_short_after_long_arg` test more realistic
2021-05-27 05:14:50 +05:30
Pavan Kumar Sunkara
6a395d3208 ArgMacthes::is_present should not deal with subcommands at all, fixes #2494 2021-05-26 00:40:38 +01:00
Ajeet D'Souza
5809ae6060
feat: Add AppSettings::DisableEnv (#2493)
* Add DisableEnv flag

* Apply formatting

* Add tests
2021-05-21 00:47:47 +05:30
Ajeet D'Souza
460459c771
fix(usage): Move positional args to end of usage string (#2492)
* Move positional args to end of USAGE

* Remove -- from usage string
2021-05-21 00:29:21 +05:30
Eldritch Cheese
fa991754d3 imp(validator): Case-insensitive required_if_eq when arg is case-insensitive 2021-05-15 09:45:24 -07:00
Peter Kolloch
e89f1e6c4d Input.insert: No need to clone 2021-05-13 13:29:01 +02:00
liudingming
529c55f753 Relax trait bound on clap Error source 2021-05-08 01:56:13 +08:00
liudingming
64e226ef33 Add multiple_* parsing for yaml 2021-05-07 14:34:03 +08:00
sharnoff
5ec28b6093
add missing $crate:: in clap_app! 2021-04-25 19:00:19 -07:00
Pavan Kumar Sunkara
9c99c358c6
Merge pull request #2440 from reaganmcf/app-setting-subcommand-help-long-form
setting: UseLongFormatForHelpSubcommand
2021-04-13 04:42:51 +05:30
Reagan McFarland
b184dc001b setting: SubcommandHelpShowsLongForm implemented
Refactoring and better test cases

Refactored SubcommandHelpShowsLongForm to
UseLongFormatForHelpSubcommand.
Tests and docuemntation examples use about and long_about instead of
(before/after)_help.

Removed commented out tests

Linting: Fix trailing new line

Updated change log, refactored tests and doc str

Reordered items in the Changelog
New test added and old tests removed that were redundant
Doc string for AppSettings::UseLongFormatForHelpSubcommand fixed
2021-04-11 14:31:40 -04:00
Pavan Kumar Sunkara
3c9cc0cf91 Specify dep patch versions 2021-04-11 10:38:13 +01:00
Pavan Kumar Sunkara
52814b893c
Merge pull request #2415 from cbzehner/ignore-extra-fields-on-arg
Ignore extra fields in Arg yaml definitions
2021-03-14 14:00:30 +05:30
Pavan Kumar Sunkara
4e3b4589ee
Merge pull request #2411 from clap-rs/upgrader
Cleanup and add changelog
2021-03-14 14:00:16 +05:30
Chris Zehner
407e629523 Ignore extra fields in Arg yaml definitions 2021-03-13 19:46:38 -06:00
Pavan Kumar Sunkara
d9fb11eba2 Apply cargo-intraconv 2021-03-13 14:11:47 +05:30
Pavan Kumar Sunkara
f029047c03 Rename NoEmptyValues to ForbidEmptyValues 2021-03-13 12:05:34 +05:30
ldm0
d36b201fd6 Apply suggestions 2021-03-11 05:22:08 +00:00
ldm0
a1d4bd8488 Allow empty value by default, introduce NoEquals Error 2021-03-10 17:39:50 +00:00
Pavan Kumar Sunkara
30d784ffd1
Merge pull request #2400 from ldm0/unset-default
Support unsetting/removing the default if an option/flag is set
2021-03-10 18:13:52 +05:30
ldm0
448ff95fb0 ldm0's patch 2021-03-09 19:06:44 +00:00
Steven Engler
766dec8319 fixup! feat(build/arg/mod.rs): default_vals_if supports an Option as the default 2021-03-09 18:15:20 +00:00
Steven Engler
6626365359 feat(build/arg/mod.rs): default_vals_if supports an Option as the default 2021-03-09 18:15:20 +00:00
ldm0
2b0f0d3e1a Implement NoEquals error 2021-03-09 17:56:57 +00:00
Pavan Kumar Sunkara
42c03775b5
Merge pull request #2395 from loloicci/improve-doc-error-exit
Improve the document of exit of parse::Errors
2021-03-09 23:20:04 +05:30
loloicci
06c2187f9e docs: improve the document of exit of parse::Error 2021-03-09 23:37:45 +09:00
ldm0
0b1d137ee9 Apply suggestions 2021-03-09 13:52:12 +00:00
ldm0
6df56ad289 Move checker to macro(better panic message) 2021-03-09 13:45:11 +00:00
ldm0
886b873709 Demangle interlinking flags 2021-03-09 13:45:11 +00:00
ldm0
2bedad2bfa Split debug_asserts from Arg 2021-03-09 13:45:11 +00:00
loloicci
0a6f086b8e feat: implement print to parse::Error
Implement print to parse::Error.
It just prints formatted error messages and does not exit program.
2021-03-09 18:27:04 +09:00
Pavan Kumar Sunkara
09009761ec
Merge pull request #2368 from integer32llc/more-getters
Allow getting the long about, env, and default values of an argument
2021-03-05 22:53:28 +05:30
Jake Goulding
30840d6f35 Allow getting the long about, env, and default values of an argument
Closes #2367
2021-03-05 11:02:18 -05:00
Christoph Prokop
676a2d24b6 Fix code example to match help text
Signed-off-by: Christoph Prokop <christoph.prokop@mailbox.org>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Reviewed-by: Matthias Beyer <mail@beyermatthias.de>
2021-03-05 10:04:37 +01:00
dylni
8a6881169b Upgrade os_str_bytes 2021-03-01 17:58:53 -05:00
Omar El Halabi
701a4610b3 feat: Implement Arg::required_if_eq_all 2021-02-28 14:52:34 +02:00
Logan SQUIREL
3c049b4e22
Fix compatibility with help2man output (see #1432)
Change default help template:
- The new template introduce new lines before and after
author/about sections.
- Add help template placeholders:
    - about-section
    - author-section
- Documentation of new placeholders in clap::App::help_template
- Update all unit tests by incorporating new lines
2021-02-27 16:20:52 +01:00
Andreas Molzer
c6ea3720ab Optimize common case of space padding 2021-02-25 13:26:39 +01:00
Logan SQUIREL
f74af655ce
Apply @pksunkara review 2021-02-22 09:37:29 +01:00
Logan SQUIREL
22b5d34693
imp: Visible aliases for arguments in completions (#2335)
Following changes are implemented:

- Add 'clap::Arg::get_visible_aliases(&self)' method
  This new method provides access to visible argument aliases
- Add 'clap::Arg::get_short/long_and_visible_aliases
  This new method provides access to the short/long arguments and its
  visible aliases
- Add visible aliases completions in clap_generate for following shells:
  - Bash
  - Elvish
  - Fish
  - Powershell
  - Zsh
- Add test fixtures for testing visible alias completions in clap_generate:
  'clap_generate/tests/completions/<shell>::<shell>_with_aliases()'
2021-02-22 09:36:08 +01:00
Pavan Kumar Sunkara
1602b103cd
Fix typo in crate_license docs 2021-02-20 22:08:48 +00:00
Martin Geisler
df7a8c1282 feat: remove direct unicode-width dependency
This removes the direct dependency on unicode-width and delegates the
complexity of computing the displayed width of text to the Textwrap
crate.

The `display_width` function handles characters like “æøå” (Danish),
“äöü” (German), and “😂😍” (emojis) – even if the unicode-width
Cargo feature is disabled.

This is an improvement of the former `str_width` function which would
over-estimate the width of emojis and non-ASCII characters (since they
are several bytes wide).
2021-02-20 20:56:15 +01:00
Pavan Kumar Sunkara
80cbc1e695
Merge pull request #2350 from ldm0/num_vals
Change how num_vals, min_vals, max_vals interacts with Multiple*
2021-02-18 21:07:26 +00:00
ldm0
2d26f02605 Add --all-features for CI, fix build with debug feature. 2021-02-17 04:37:08 +00:00
ldm0
28b58af63b Change to num_vals, min_vals, max_vals interacts with Multi* 2021-02-16 03:45:20 +00:00
Collin Styles
2b45011c9b
Update docs for required_unless_present_any (#2347)
* docs: Correct method name in example

This looks like it was copied from the documentation for
`required_unless_present_all` but not updated accordingly for this
method.

* docs: Add note re `required_unless_present_all` to `required_unless_present_any`

There's a note in the documentation for `required_unless_present_all`
telling users to check out `required_unless_present_any` if that's what
they want. I figured it might be useful to have a similar note in the
documentation for `required_unless_present_any` pointing to that method
as well.

* docs: Fix `required` link in docs for `required_unless_present_all`

* docs: Correct "if" to "unless"
2021-02-15 08:20:11 +00:00
ldm0
73c682b652 Small code shrinking 2021-02-14 13:07:21 +00:00
ldm0
5cff16b6f9 Limit usage of inc_occurence_of 2021-02-14 11:21:12 +00:00
ldm0
78d7252b03 Remove Parser::need_more_vals 2021-02-14 11:21:12 +00:00
Pavan Kumar Sunkara
a8c9d28ead
Merge pull request #2346 from ldm0/non_fmt_panic_fix
Fix part of the non_fmt_panic warnings, bump version-sync to 0.9.2
2021-02-14 01:58:26 +00:00
Pavan Kumar Sunkara
5025ed3bee
Merge pull request #2345 from ldm0/usize
Change some u64 to usize
2021-02-14 01:57:53 +00:00
ldm0
ddb53af5dc Change some u64 to usize 2021-02-13 15:25:40 +00:00
ldm0
580d8d2c63 Fix part of the non_fmt_panic 2021-02-12 17:35:15 +00:00
Pavan Kumar Sunkara
6634444c3c Remove Arg::settings to be consistent with App 2021-02-12 10:42:38 +00:00
Pavan Kumar Sunkara
8eb5081b53 Update changelog 2021-02-10 23:33:14 +00:00
Pavan Kumar Sunkara
2b5a23597a Better help message support for hidden and heading stuff 2021-02-08 05:22:27 +00:00
Pavan Kumar Sunkara
3758bba5e2 Remove help_about in favor of mut_arg 2021-02-07 17:22:56 +00:00
Pavan Kumar Sunkara
b824e0b088 Allow nested subcommands mutated generated args to take preference 2021-02-07 16:28:49 +00:00
Pavan Kumar Sunkara
423e2dde00 Remove version_about in favor of mut_arg 2021-02-07 16:14:07 +00:00
Pavan Kumar Sunkara
1bd902370a Add tests for mut_arg on help and version 2021-02-07 15:54:24 +00:00
Pavan Kumar Sunkara
93a737a4fa
Merge pull request #2333 from clap-rs/build_help_and_version_at_start
Build help and version args at the beginning
2021-02-07 15:53:45 +00:00
Pavan Kumar Sunkara
c9cb22905c Build help and version args at the beginning 2021-02-07 14:46:38 +00:00
ldm0
899b04f481 Remove clone 2021-02-07 05:40:02 +00:00
ldm0
1494109795 Apply rename suggestions 2021-02-07 05:32:35 +00:00
ldm0
fb3033834b Change the way parser do self override 2021-02-07 04:46:56 +00:00
Donough Liu
58b9f35771 Add tests, fix grouped_values_of()
Fix clippy

type complexity fix
2021-02-07 04:46:56 +00:00
Donough Liu
451c5382cc Finish arg grouping logic 2021-02-07 04:46:56 +00:00
Donough Liu
b48ccff812 Better MatchedArg::ty 2021-02-07 04:46:56 +00:00
Donough Liu
fdafa3f02a More convenient MatchesArg functions 2021-02-07 04:46:56 +00:00
Donough Liu
7782a5eefc Insert vals group for default missing vals 2021-02-07 04:46:56 +00:00
Donough Liu
32e03a0dfe Better flow 2021-02-07 04:46:56 +00:00
Donough Liu
f1e9b82584 Implement nested vals 2021-02-07 04:46:56 +00:00
Donough Liu
9c52e454e8 Refactor MatchedArg::vals 2021-02-07 04:46:56 +00:00
Donough Liu
18549df845 Refactor MatchedArg::indices 2021-02-07 04:46:56 +00:00
ldm0
1000c9fb03 Fix eagerly trimming dash in parse_long_flag 2021-02-06 11:26:20 +00:00
Donough Liu
00cf697d36 Small simplification on several functions 2021-02-05 10:07:46 +00:00
Donough Liu
5e020c636d Remove had_eq 2021-02-05 10:07:46 +00:00
Donough Liu
751adaa687 Remove ContainsLast flag 2021-02-05 10:07:46 +00:00
Donough Liu
818f62bd5c Unused clippy allow 2021-01-30 17:39:34 +00:00
Donough Liu
45753d552b Resolve a TODO 2021-01-30 17:39:34 +00:00
Donough Liu
cf4881182a Add comments for some internal app settings 2021-01-30 17:39:34 +00:00
Donough Liu
c8e669c690 Eliminate unreachable branch
comment fix

Apply fmt
2021-01-30 17:39:33 +00:00
Donough Liu
944fc759c9 Optimize branch, more comments 2021-01-30 17:24:11 +00:00
Donough Liu
5774eb2c52 Simplify possible subcommand 2021-01-30 17:24:11 +00:00
Donough Liu
9cf007378b Branch simpification 2021-01-30 17:24:11 +00:00
Donough Liu
336f926ec9 Integrate workflow 2021-01-30 17:24:11 +00:00
Donough Liu
be314d9ac0 Flow optimize 2021-01-30 17:24:11 +00:00
Donough Liu
c39dcf2ecf Remove redundant ClapResult in some functions 2021-01-30 17:24:11 +00:00
Donough Liu
1b63516e3b Flow reordering 2021-01-30 17:24:11 +00:00
Donough Liu
47eee8ab2f Acc a request 2021-01-30 17:24:11 +00:00
Donough Liu
c6bcfe819e Clearer error processing 2021-01-30 17:24:11 +00:00
Donough Liu
8f4c26fc58 Minor redundant logic cleanup
Fix clippy

dot fix
2021-01-30 17:24:09 +00:00
Pavan Kumar Sunkara
8d5a021e1e
Merge pull request #2309 from ldm0/parser0
Dehack, Revert #1856
2021-01-30 14:52:02 +00:00
ldm0
5ee6e07858 Fix usage of positional grouped arguments uses arg name rather than val_name 2021-01-24 19:02:43 +00:00
Donough Liu
0df169bbdc Fix incorrect error message.
Comment out regressed logic

Fix clippy
2021-01-23 14:51:40 +00:00
Donough Liu
90d786b8bc Dehack, revert #1856 2021-01-23 14:51:40 +00:00
Pavan Kumar Sunkara
d7f6748887
Merge pull request #2306 from ldm0/unset_setting
Fix unset_setting()
2021-01-23 13:37:57 +00:00
Bowen Ding
3907e11621
Make @group accept multiple attributes (#2248)
* Make @group accept multiple attributes.

* New syntax: remove parenthese and "=>".

* Fix example

* Make Clippy happy

* Make clippy happy again
2021-01-23 13:12:40 +00:00
ldm0
68a0ef930a Fix copied code 2021-01-23 06:41:11 +00:00
AriusX7
448c102f4f fix: allow visible alias(es) in yaml files 2021-01-20 02:17:17 +05:30
Pavan Kumar Sunkara
42a4087220
Merge pull request #2299 from ldm0/terminator
Pick up missing setting
2021-01-18 22:13:20 +00:00
Donough Liu
09f43594b9 Fix doc test 2021-01-19 02:39:16 +08:00
Donough Liu
acdb94c1a5 Add assert to make doc test fails. 2021-01-19 02:37:07 +08:00
Donough Liu
6968f340c3 Fix clippy warnings 2021-01-19 02:24:58 +08:00
Donough Liu
c6da968ec7 Bump textwrap to 0.13.2 2021-01-02 13:15:50 +08:00
Martin Geisler
72884b2642 docs: Mention correct default value in term_width docstring
The default was correctly changed to 100 in #1950, but later
accidentally reverted in 89fcc75.
2020-12-31 08:55:56 +01:00
Pavan Kumar Sunkara
a0269a41d4
Merge pull request #2268 from ldm0/fixme
Better mkeymap
2020-12-28 10:09:27 +00:00
Donough Liu
0f115f18ad Fix positional count usage 2020-12-27 04:11:30 +08:00
Donough Liu
120e942e7a Private arg 2020-12-27 01:46:48 +08:00
Donough Liu
2b7fd731ae Private keys 2020-12-27 01:20:53 +08:00
Donough Liu
f54328ee4c Cleaner api and better inner documentation 2020-12-27 00:43:49 +08:00
Donough Liu
53fdc9d6b2 Fix clippy 2020-12-26 21:03:21 +08:00
Donough Liu
ad3d3a13cd KeyType: PartialEq for u64 2020-12-26 21:03:21 +08:00
Donough Liu
b2a066b24f Resolve a fixme, better code readability 2020-12-26 21:03:21 +08:00
budde25
c26d1a4421 imp: added more derives to common App, Arg, and ArgMatches 2020-12-23 17:26:53 -06:00
budde25
52635f00d4 docs(arg_matches.rs): clarified unclear behavior for is_present and value_of methods 2020-12-23 07:44:19 -06:00
Pavan Kumar Sunkara
4bd15c45d2
Merge pull request #2253 from ldm0/global
Propagate global arg in subcommand to subsubcommand
2020-12-14 02:20:34 +00:00
Pavan Kumar Sunkara
c4ab996339
Merge pull request #2252 from ldm0/lazy_propagation
Lazy propagation and _build cleaning
2020-12-12 16:56:09 +00:00
Donough Liu
1965b9f866 Add BinNameBuilt flag to App 2020-12-13 00:11:12 +08:00
Donough Liu
2f9846d048 Lazy subcommand propagation, avoid redundant _build() function call
rustfmt and clippy

Indepth cleaning

Apply suggestions
2020-12-12 22:32:20 +08:00
Donough Liu
fa9be84b18 Propagate global arg in subcommand to subsubcommand 2020-12-12 22:20:16 +08:00
Donough Liu
5f5474d803 Fix only one arg printed in multiple required_unless missing situation 2020-12-12 12:57:17 +08:00
Donough Liu
6fdad97a90 Remove unused flag 2020-12-10 00:58:11 +08:00
Donough Liu
e58f89b3ab Remove LowIndexMultiplePositional, stop repeatedly calc positional_count 2020-12-10 00:51:18 +08:00
Robin Moussu
6898fbde33 Automatically read license field from Cargo.toml 2020-12-09 00:16:19 +01:00
Donough Liu
573dc245e6 Fix incorrect error message. 2020-12-09 01:12:58 +08:00
Jonas Platte
041bfda7ca
Fix a typo in the Clap trait docs (#2243)
* Fix a typo in the Clap trait docs

* Update src/derive.rs

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-12-08 01:40:18 +00:00
Pavan Kumar Sunkara
3c93f276b5
Merge pull request #2230 from ahkrr/master
refactor: TODO 1.46.0, improve readability by using [] operator
2020-11-28 13:11:50 +00:00
Pavan Kumar Sunkara
c8184470ff
Merge pull request #2140 from ldm0/validator_fixme
Resolve a FIXME
2020-11-28 13:11:38 +00:00
Pavan Kumar Sunkara
b89163afb6 Update MSRV to 1.46 2020-11-28 11:58:28 +00:00
hk
bb7c9896b0 refactor: TODO 1.46.0, improve readability by using [] operator 2020-11-28 11:38:34 +01:00
Donough Liu
cad893ed04 Resolve a FIXME 2020-11-28 18:31:42 +08:00
arthmis
a97e24630d chore: changing unrequired to non-required 2020-11-27 15:37:26 -05:00
arthmis
1b4a4596f6 docs: fixing a typo 2020-11-27 15:19:03 -05:00
arthmis
4e6a371851 chore: changing awkward grammar for positional argument error message 2020-11-27 15:12:28 -05:00
Pavan Kumar Sunkara
d36d91173d
Merge pull request #2191 from ahkrr/master
fix(clap_generate): zsh completion generation panic
2020-11-26 18:36:41 +00:00
Pavan Kumar Sunkara
821d79aac7
Merge pull request #1878 from lu-zero/update_from_arg_matches
Add update_from_arg_matches to FromArgMatches
2020-11-14 12:38:16 +01:00
Luca Barbato
3e51839383 Rename the update trait methods 2020-11-14 10:58:30 +01:00
Luca Barbato
5d342a7438 Update to the new from_subcommand logic 2020-11-14 10:17:13 +01:00
Luca Barbato
a9276576d7 wip: Add a variant for augment* for updates 2020-11-14 10:17:13 +01:00
Luca Barbato
8b6255057d wip: Complete update_subcommand
external subcommand updating is equivalent to replace it
2020-11-14 10:17:13 +01:00
Luca Barbato
646b3fe811 wip: Add tests and user-facing functions 2020-11-14 10:17:13 +01:00
Luca Barbato
d1fc83a8fa wip: Add update_from_arg_matches to FromArgMatches 2020-11-14 10:17:13 +01:00
hk
895c903b61 refactor: adding get_global, making two functions private
preserving the observable behavior of the existing 
public api, while handling global arguments separately in 
get_arg_conflicts_with
2020-11-09 15:29:00 +01:00
ldm0
ff3b23824d Fix wrong StrictUTF8 handling when AllowExternalSubcommands 2020-11-08 19:06:32 +00:00
Donough Liu
93b9bd9162 Apply suggestions 2020-11-08 23:06:24 +08:00
Donough Liu
407cdac8e0 Refactor: remove a persistent parser state ValidNegNumFound 2020-11-08 16:05:07 +08:00
Donough Liu
3c2f60c9f3 Remove unreachable branch in use_long_arg() 2020-11-08 16:05:07 +08:00
Donough Liu
7aa2358d6e Simplify is_new_arg() 2020-11-08 16:05:07 +08:00
Donough Liu
b1c7785810 Remove replace variable
Resolve TODO

Small refactors

More descriptive replaced item recovering
2020-11-08 16:05:03 +08:00
Donough Liu
5e4b4f4196 Remove invalid suggestion on using subcommand after positional argument 2020-11-07 20:32:28 +08:00
Donough Liu
2b1f47f975 Reduce osstring construction 2020-11-07 16:43:14 +08:00
Donough Liu
020b07b77b Typo fix 2020-11-07 16:43:14 +08:00
Donough Liu
582db739c8 Shrink 2020-11-07 16:43:14 +08:00
Donough Liu
f17b29acbb Make Arg::env() and Arg::env_os() takes_value(false) by default 2020-11-06 21:51:39 +01:00
hk
5650e37969 fix: compatability with rustc 1.42.0
fixup!
2020-11-05 13:08:04 +01:00
hk
1b451f62ad fix(clap_generate): zsh completion generation panic
zsh completion generation would panic if a global argument 
had conflicts with another argument which was present in its 
own command but not in its subcommands
2020-10-30 21:04:17 +01:00
bors[bot]
97b4fb639f
Merge #2165
2165: Help & Version settings r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-10-28 06:27:49 +00:00
Pavan Kumar Sunkara
5dd9584119 Improve the logic for help & version building & parsing 2020-10-26 12:13:03 +01:00
Donough Liu
a19bfa1c35 Consistently wrap help and subcommand messages(with refactoring) 2020-10-25 22:43:01 +01:00
KBR9
625c201f65 Add docs about conflicts_with_all usage in yaml
add note about conflicts_with yaml option

add note about conflicts_with yaml option

fix wrapping

remove unnecessary sentence

remove note from conflicts_with
2020-10-24 21:54:01 +02:00
Pavan Kumar Sunkara
e8a06e79cd Rename setting VersionlessSubcommands => DisableVersionForSubcommands 2020-10-24 16:04:49 +02:00
Pavan Kumar Sunkara
d6e2246aab Rename setting DisableVersion => DisableVersionFlag 2020-10-24 16:03:12 +02:00
Pavan Kumar Sunkara
45f0ee8b55 Rename setting DisableHelpFlags => DisableHelpFlag 2020-10-24 16:03:12 +02:00
CastilloDel
88ac1f1803 Add assertions for required and default simultaneously
Add the suggested changes

Fix test issue_1050_num_vals_and_defaults

It used a required which isn't needed for the purpose of the test.

Add tests for the default+required assertions

Add test for positional args with long or short
2020-10-24 12:10:07 +01:00
bors[bot]
1d0b21908f
Merge #2178
2178: Various documentation fixes r=pksunkara a=cstyles



Co-authored-by: Collin Styles <collingstyles@gmail.com>
2020-10-18 22:08:05 +00:00
Collin Styles
0d4e2e5f9d docs: remove links in documentation for requires_all
These links were broken but rather than fix them, let's just remove them
since they're inside the documentation for the function that they link
to which seems unnecessary.
2020-10-18 12:05:33 -07:00
Collin Styles
5b74d84f3c docs: remove links in documentation for requires_if functions
These links were broken but rather than fix them, let's just remove them
since they're inside the documentation for the functions that they link
to which seems unnecessary.
2020-10-18 12:05:32 -07:00
Collin Styles
3d5e1d987a docs: add a bunch of missing links to the docs for Arg::env 2020-10-18 12:05:31 -07:00
Collin Styles
ba89a253fc docs: remove link to allow_hyphen_values
This link was broken but rather than fix it, let's just remove it since
it's inside the documentation for the function that it links to which
seems unnecessary.
2020-10-18 12:05:30 -07:00
Collin Styles
8522b9c1cf docs: fix another typo and add a missing link for Last 2020-10-18 12:05:29 -07:00
Collin Styles
eadecc5c1d docs: add missing link in ArgGroup documentation 2020-10-18 12:05:28 -07:00
Collin Styles
096338d163 docs: correct typo in ErrorKind documentation 2020-10-18 12:05:27 -07:00
Collin Styles
75c1fdb707 docs: fix various copy-paste errors related to default_value functions 2020-10-18 12:05:26 -07:00
Collin Styles
f7837b2ac0 docs: change single quotes to backticks
Pretty sure these are just typos.
2020-10-18 12:05:25 -07:00
Collin Styles
9f3cbcd149 docs: wrap Arg in backticks instead of quotes
This looks better and is more consistent with the rest of the
documentation.
2020-10-18 12:05:22 -07:00
Collin Styles
b3caf81918 docs: fix a bunch of broken documentation links 2020-10-18 12:05:19 -07:00
CastilloDel
acd3293af2 Add an assertion for positional args defining long or short
Also update the docs to reflect that Arg.index shouldn't be
used with long or short
2020-10-18 19:51:13 +01:00
Jacob Mischka
b3e638ad44
Add option to hide autogenerated env section from help text 2020-10-17 16:48:35 -05:00
bors[bot]
d2dd54b555
Merge #2172
2172: Don't use default value when option is passed r=pksunkara a=davidhewitt



Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2020-10-14 20:54:10 +00:00
David Hewitt
94f6889116 Don't use default value when option is passed 2020-10-14 20:00:40 +01:00
Wim Looman
b31df047b8 Attach validation error as Error::source 2020-10-13 22:13:04 +02:00
bors[bot]
5a1a209965
Merge #2161
2161: Fix parser skipping options without heading set r=pksunkara a=CertainLach



Co-authored-by: Yaroslav Bolyukin <iam@lach.pw>
2020-10-11 08:55:33 +00:00
Donough Liu
7f627fceee Change MissingArgumentOrSubcommand to DisplayHelpOnMissingArgumentOrSubcommand and don't use stderr 2020-10-11 15:42:47 +08:00