Commit graph

4203 commits

Author SHA1 Message Date
Richard Maw
636ecaffa2 fixup! make new tests compile but not run without unstable-multicall 2021-10-15 20:59:33 +01:00
Ed Page
bfd6f8d8e0
Merge pull request #2884 from epage/augment
fix(derive): Support 'update' with 'flatten'
2021-10-15 14:47:12 -05:00
Richard Maw
f7e9bfed80 fixup! Add unstable-multicall flag to CI workflows 2021-10-15 20:27:29 +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
Ed Page
22edac66d9 fix(derive): Ensure App help_heading is applied
We normally set all app attributes at the end.  This can be changed but
will require some work to ensure
- Top-level item's doc cmment ins our over flattened
- We still support `Args` / `Subcommand` be used to initialize an `App` when
  creating a subcommand

In the mean time, this special cases `help_heading` to happen first.
We'll need this special casing anyways to address #2803 since we'll need
to capture the old help heading before addings args and then restore it
after.  I guess we could unconditionally do that but its extra work /
boilerplate for when people have to dig into their what the derives do.

Fixes #2785
2021-10-15 14:19:16 -05:00
Ed Page
7b3d3401c0 fix(derive): Support 'update' with 'flatten'
When working on #2803, I noticed a disprecancy in the augment
behavior between `Arg`s and `Subcommand`s that makes it so `Arg`s can't
be flattened with the update functionality.
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
bors[bot]
4854986bb9
Merge #2883
2883: fix(app): Rename generaet_usage to render_usage r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 15:54:13 +00: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
bors[bot]
cd00a9408a
Merge #2878
2878: fix: Give Arg::help_heading priority over App::help_heading r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-15 07:36:19 +00: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]
089c4160cf
Merge #2879
2879: Improve bash generator r=pksunkara a=pksunkara



Co-authored-by: Ajeet D'Souza <98ajeet@gmail.com>
2021-10-14 22:04:07 +00:00
Ajeet D'Souza
cad1879ab2 Improve bash generator 2021-10-14 22:51:40 +01: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
bors[bot]
19b920a5dc
Merge #2874
2874: fix: Apply app help heading in App::args() r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-14 19:12:04 +00:00
Nicolas Stinus
bcf1bb69c8 fix(gen): address clippy suggestion
Change-Id: I11a8dc27956e6365a0c8ae8165e08d2209ae9395
2021-10-14 14:42:04 -04:00
Nicolas Stinus
de1c764905 fix(gen): in bash, pass use possible_values if available
Change-Id: I7a54821666f0ba366379d6cac83898fcd9b76ee6
2021-10-14 14:41:11 -04: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
bors[bot]
c5296977e5
Merge #2867
2867: fix(help)!: Merge OPTIONS / FLAGS default groups r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-13 21:39:15 +00: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
bors[bot]
1f17d9e8ba
Merge #2851
2851: fix!: Make color settings an enum r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-10-13 13:03:28 +00: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
Richard Maw
694329b363 fixup! Make hostname a non-derive example and rename via Cargo.toml 2021-10-12 22:38:43 +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
bors[bot]
5f3fe4921a
Merge #2859
2859: Partial Revert of "Change MissingArgumentOrSubcommand to DisplayHelpO… r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 20:16:27 +00:00
Richard Maw
b808729bbc fixup! Fill in tracking issue number 2021-10-12 20:51:26 +01:00
Richard Maw
b2180e9d72 fixup! Gate Multicall behind unstable feature 2021-10-12 20:35:59 +01:00
bors[bot]
93decf7424
Merge #2858
2858: Get Fig compiling and testing r=epage a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 19:09:52 +00: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
Richard Maw
a31d3b288d fixup! Revert: Make hostname a non-derive example and rename via Cargo.toml
tests/examples.rs:examples_are_functional finds examples by stripping
`.rs` off the basename
2021-10-12 20:01:59 +01:00
Richard Maw
1782f9d4ec fixup! Make hostname a non-derive example and rename via Cargo.toml 2021-10-12 19:57:32 +01:00
Ed Page
a61752a5d5 chore: Include fig in testing 2021-10-12 11:25:17 -05:00
Ed Page
d8b6016f57 fix(fig): Get tests passing 2021-10-12 11:00:34 -05:00
Ed Page
fa0deb03cf fix(fig): Get compiling 2021-10-12 11:00:34 -05:00
bors[bot]
1f958fab2e
Merge #2849
2849: Parser redux r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 15:57:23 +00:00
bors[bot]
36e172672c
Merge #2855
2855: fix(gen)!: Simplify `Generator` trait r=pksunkara a=epage



Co-authored-by: Ed Page <eopage@gmail.com>
2021-10-12 14:50:55 +00:00
Ed Page
536471cb7d fix(gen)!: Simplify Generator trait
This is a followup to #2721 where we decided to remove all of the
helpers from the trait.  They are now in a `utils` mod.  A part of me
wants this module to be private but it'd be a lot to duplicate for the
split out modules.

Note: this doesn't update fig.  Fig was never added to the workspace and
is already broken (and not just from #2721).  My plan is to get this
merged and then fix Fig, rather than fix it in multiple passes.
2021-10-12 08:27:24 -05:00
Ed Page
60c9c2e59a docs(derive): Use more-specific traits
This helps to raise visibility of the new derive traits.

I didn't touch ui tests because there were a lot and they didn't seem to
be as high value.
2021-10-12 07:51:11 -05:00
bors[bot]
ab050441de
Merge #2829
2829: [clap_generate] [zsh] sort out multiple occurrence vs multiple_value. r=pksunkara a=pseyfert



Co-authored-by: Paul Seyfert <Paul.Seyfert@sevensense.ch>
2021-10-12 10:00:06 +00:00
Paul Seyfert
25e337adb1 [clap_generate] [zsh] sort out multiple occurrence vs multiple_value. 2021-10-12 10:48:37 +01:00