Commit graph

215 commits

Author SHA1 Message Date
Ed Page
83db04c0c3 docs: Update changelog 2022-09-29 12:08:40 -05:00
Martin von Zweigbergk
33fa7c4c19 fix(complete): Fix command alias and Bash
With the previous fixes for #4273 and #4280 in place, it's now easy to
add support for subcommand aliases, which this commit does. This
addresses #4265 for Bash.
2022-09-29 08:58:32 -07:00
Martin von Zweigbergk
9ee45f7f3d fix(complete): Fix git diff log <TAB> for Bash
This continues the work started with the fix for #4273. There was
another bug caused by using the subcommand names without considering
their position in the argument list. If the user enters `git diff log
<TAB>`, we build up a string that identifies the subcommand. We ended
up making the string `git__diff__log` in this case because we appended
`__log` without considering the current state. Since `git__diff__log`
does not correspond to an actual command, we wouldn't provide any
suggestions.

This commit restructures the code so we walk subcommands and
subsubcommands in `bash.rs`. While walking those, we build up a list
containing triples of the parent `$cmd` name (e.g. `git__diff`), the
current command's name (e.g. `log`), and the `$cmd` for the current
command. We then build the shell script's case arms based on that
information.

We could instead have fixed #4280 by using the second element in the
pair returned from `utils::all_subcommands()` (a stringified list of
the subcommand path) instead of the first one. However, that would not
have helped us solve #4265.

Closes #4280
2022-09-29 08:58:32 -07:00
Martin von Zweigbergk
ea264fde16 fix(complete): Fix git diff git <TAB> for Bash
Early in the Bash-completion script, we build up a string that
identifies the command or subcommand. When we see the top-level
command's name (e.g. `git`) we set the command so far to that
value. We do that regardless of where in the argument list it
appears. For example, if the argument list is `git diff git`, we set
the current command to `git` when run into it the second time. We
therefore suggest arguments to the top-level command afterwards, which
is not correct.

This patch fixes that by also considering the string that identifies
the command so far, so we only set the overall command to `git` if the
command so far is the empty string.

This is actually just a step on the way to getting completion to work
for aliases of subcommands.

Closes #4273
2022-09-29 08:40:54 -07:00
Martin von Zweigbergk
35b5f9b276 refactor(complete): Remove an always-true check
The `text` variable here is clearly never empty, so don't check if it
is.
2022-09-29 08:40:54 -07:00
Martin von Zweigbergk
9c59c69bb0 refactor(complete): Remove unnecessary early return
There seems to be little reason to return early with an empty list
when there are no subcommands, instead of going through the loop 0
times and then returning the empty list.
2022-09-29 08:40:54 -07:00
Martin von Zweigbergk
8d0ef124e0 test(complete): Include a visible command alias
Only zsh includes completion for visible aliases of subcommands. Let's
show that in tests.
2022-09-29 08:40:54 -07:00
Martin von Zweigbergk
5020d739d5 refactor(complete): Add an alias for the subcommand
I want to add support for completion of arguments for aliased
subcommands so it's nice to have an example to test on.
2022-09-29 08:39:49 -07:00
Martin von Zweigbergk
6bc8d2632c refactor(complete): Add a subcommand to examples
It's useful when testing to have a subcommand in the examples.
2022-09-29 08:39:17 -07:00
Martin von Zweigbergk
8b33da3138 fix(complete): Make the two examples consistent
The derive-based example has a `///` comment on one argument, which
ends up as a description for the argument in the generated completion
scripts. Let's switch to `//` so the two scripts produce the same
output (except for the binary name), so they're easy to compare.
2022-09-29 08:37:03 -07:00
Martin von Zweigbergk
59270b1c81 fix(complete): Make example commands match binary
The example binaries were renamed in 89c2b3bb0d, but the commands in
them were not, making the generated completion scripts not work
(because we use the command name as binary name in the examples).
2022-09-29 08:34:19 -07:00
Ed Page
bf42ff04d5 chore: Release 2022-09-28 15:34:33 -05:00
Ed Page
824f6589ad docs: Update changelog 2022-09-28 15:34:25 -05:00
Ed Page
7b886d2c63
Merge pull request #4278 from intgr/zsh-completion-fix-multiple-args-handling
fix(complete): Fix zsh handling of multiple arguments
2022-09-28 15:33:42 -05:00
Marti Raudsepp
89cae3a2b3 fix(complete): Fix handling of multiple arguments 2022-09-28 23:02:31 +03:00
Ed Page
8aafddff01 docs(complete): Ensure examples work
Fixes #4272
2022-09-28 14:34:56 -05:00
Ed Page
3a74d82376 chore: Release 2022-09-28 12:00:48 -05:00
Ed Page
a82029c707 chore: Release 2022-09-20 16:30:29 -05:00
Ed Page
af64699912 chore: Release 2022-09-20 16:28:27 -05:00
Ed Page
7a5dad89ff feat(help): Break out help feature flag
This removes auto-generated help, saving about 50 KiB.
2022-09-19 11:54:10 -05:00
Ed Page
c165b601ac perf: Switch to &'static str by default
Originally, clap carried a lifetime parameter.  When moving away from
that, we took the approach that dynamically generated strings are always
supported and `&'static str` was just an optimization.

The problem is the code size increase from this is dramatic.  So we're
taking the opposite approach and making dynamic formatting opt-in under
the `string` feature flag.  When deciding on an implementation, I
favored the faster one rather than the one with smaller code size since
small code size can be gotten through other means.

Before: 567.2 KiB, 15.975 µs
After: 541.1 KiB, 9.7855 µs
With `string`: 576.6 KiB, 13.016 µs
2022-09-16 16:44:39 -05:00
Roland Fredenhagen
a2cf7f1dea fix: Tests/clippy/errors bash dynamic completion 2022-09-07 20:25:06 -05:00
Ed Page
bffce7f57a fix: Deprecate Command::trailing_var_arg
Now that we have it on `Arg`, we don't need it on `Command`
2022-09-06 19:41:17 -05:00
Ed Page
0e915e0d3a docs(derive): Update for new attributes 2022-09-02 15:39:13 -05:00
Roland Fredenhagen
8ab649e929
fix(complete): Escape , in completions for fish 2022-09-02 14:47:04 +02:00
Roland Fredenhagen
028a4cd0dc
test(complete): Disable normalization of \ to /
This allows easier testing, as the generated completion files can be
sourced directly.
2022-09-02 14:46:12 +02:00
Ed Page
6bd4fee69f chore: Update dependencies 2022-09-01 07:09:32 -05:00
Ed Page
02db3043e2 fix(help): Consistently use [] for positionals
In the usaeg we use `[]` but in the arg list we use `<>`.
2022-08-29 15:34:30 -05:00
Andrew Shu
eec047a6f6 fix(help): Do not propagate global args to help
This prevents global args from showing in help completions,
since help completions should only suggest subcommands.
Adds tests to ensure the args still show in the generated
help messages of subcommands.
2022-08-26 17:48:58 -07:00
Ed Page
294868f5d8
Merge pull request #4115 from talklittle/completion-help-parser-flag
feat(complete): Add completion for help subcommands
2022-08-26 15:28:21 -05:00
Andrew Shu
0d0be51606 fix(complete): Fix help completion issues
* Copy hide flag

* Revert global args special handling. Another commit will
address the issue of whether global args should be included in
help subtrees.
2022-08-26 12:57:12 -07:00
Ed Page
b4b121d3a4 fix(derive): Remove deprecated arg_enum attribute 2022-08-26 13:34:16 -05:00
Andrew Shu
729406661c refactor(complete): Clean up help completion
* Manual subtree copy to ensure correct behavior and settings
* Always set ExpandHelpSubcommandTrees in Command::build
* Remove redundant logic
2022-08-25 15:43:27 -07:00
Andrew Shu
fdcee9313f feat(complete): Add completion for help subcommands
Adds parser flags to toggle whether to run the
expensive clone logic for completions case.

Help completion will only suggest subcommands, not args.

clap_complete generator sets the flag.
2022-08-25 13:58:08 -07:00
Ed Page
df7616b820 fix(help): Match v3 usage for optional positionals 2022-08-25 13:13:09 -05:00
Ed Page
e00abc6905 refactor(help): Consolidate arg suffix rendering
This ended up favoring the help implementation
2022-08-25 13:01:27 -05:00
Ed Page
c6155f62d5 feat: Open the door for user styling in the future
This added about 10 KiB to the `.text` which I cannot explain why
2022-08-24 18:17:42 -05:00
Ed Page
276c75cc08 fix: Don't pollute root with str types 2022-08-23 13:12:06 -05:00
Ed Page
1bbf07e574 fix: Prefer more usable &str for reflection
The downside is we can't skip allocations with
- `ValueEnum` default values
- Vaid subcommands

Otherwise, this is a big ergonomic win.
2022-08-22 14:56:16 -05:00
Ed Page
85f541d789 fix: Switch to owned types
Impact:
- Binary size: 556.6 KiB to 578.4 KiB
- build time: 6.4950 us (7% slower)
- parse time: 7.7256 us
- parse sc time: 8.1580 us (5% faster)

Fixes #1041
Fixes #2150
2022-08-22 14:55:55 -05:00
Ed Page
8cc164dafb fix!: Remove lifetime from PossibleValue
Another step towards #1041

This isn't the long term type for `PossibleValue::help`, I just wanted
to get the lifetime out of the way first before figuring out how help
will work.
2022-08-19 12:44:29 -05:00
Ed Page
43e961d24f style: Address clippy 2022-08-11 16:07:58 -05:00
Ed Page
3390adf0d3 chore: Bump MSRV to 1.60.0
While at it, this cleans up all of the features.  For some reason, I
couldn't do `dep:clap_derive` though.
2022-08-10 21:32:06 -05:00
Ed Page
f70ebe89a7 fix!: Require explicit help/version disabling
Before we introduced actions, it required specific setups to engage with
claps version and help printing.  With actions making that more
explicit, we don't get as much benefit from our multiple, obscure, ways
of users customizing help

Before
- Modify existing help or version with `mut_arg` which would
  automatically be pushed down the command tree like `global(true)`
- Create an new help or version and have it treated as if it was the
  built-in on (I think)
- Use the same flags as built-in and have the built-in flags
  automatically disabled
- Users could explicitly disable the built-in functionality and do what
  they want

Now
- `mut_arg` no longer works as we define help and version flags at the
  end
- If someone defines a flag that overlaps with the built-ins by id,
  long, or short, a debug assert will tell them to explicitly disable
  the built-in
- Any customization has to be done by a user providing their own.  To
  propagate through the command tree, they need to set `global(true)`.

Benefits
- Hopefully, this makes it less confusing on how to override help
  behavior.  Someone creates an arg and we then tell them how to disable
  the built-in
- This greatly simplifies the arg handling by pushing more
  responsibility onto the developer in what are hopefully just corner
  cases
- This removes about 1Kb from .text

Fixes #3405
Fixes #4033
2022-08-10 20:33:21 -05:00
Ed Page
64639aa81c style: Make clippy happy 2022-08-10 11:41:27 -05:00
Ed Page
8ed35b4d9f fix: Provide convenient access for common cases 2022-08-05 12:06:54 -05:00
Ed Page
32f308d4ef fix!: Make is_multiple_values private
multiple_values is now just book keeping for the builder, instead people
should look to actions and `num_args`.

The meaning for it was a little weird anyways.
2022-08-04 15:21:10 -05:00
Ed Page
6e1ca59ec1 fix!: Make is_takes_value_set private
At this point, it is an implementation detail to help with book keeping
within the builder.
2022-08-04 14:44:14 -05:00
Ed Page
52ec1f92e9 fix: Clarify that get_num_args is safe to call
The only time it won't be initialized is before `_build`.  This is possible because
of #4027

I wish I could just put the `expect` inside the call but I'm worried
about allowing people to build stuff on top of clap.
2022-08-04 14:21:53 -05:00
Ed Page
ba15b5f430 fix!: Rename Arg::number_of_values to Arg::num_args 2022-08-03 14:45:47 -05:00
Ed Page
470531b515 fix!: Replace multiple_values with number_of_values
This reduces ambiguity in how the different "multiple" parts of the API
interact and lowrs the amount of API surface area users have to dig
through to use clap.

For now, this is only a matter of cleaning up the public API.  Cleaning
up the implementation is the next step.
2022-08-01 15:50:23 -05:00
Ed Page
76bff6f34e fix!: Remove rest of deprecated APIs
Fixes #4009
2022-08-01 15:21:33 -05:00
Ed Page
41535d5c46 feat: Extend number_of_values to support min/max per occurrence 2022-07-28 16:52:25 -05:00
Ed Page
5f20fe1930 docs: Shift focus from takes_value to actions 2022-07-26 14:50:51 -05:00
Ed Page
6f03b4f948 fix!: Remove multiple occurrences in favor of Append/Count
For num_vals and friends, this only implements hacks until #2688

Fixes #3021
2022-07-25 13:23:43 -05:00
Ed Page
8aa7ab3e16 chore: Update version
The main goal is to reduce the risk of people developing on the wrong
release, assuming they are using something like starship to raise the
visibility of the crate version.
2022-07-23 21:43:37 -05:00
Ed Page
08e8642a8c
Merge pull request #3976 from epage/attrib
fix(derive)!: Remove value_parser/action defaulted attributes
2022-07-22 20:25:09 -05:00
Ed Page
6ecb7310a8 fix(derive)!: Remove value_parser/action defaulted attributes 2022-07-22 20:07:47 -05:00
Ed Page
122b562e6b fix!: Change default actions to Set/SetTrue
This is in prep for removing StoreValue/IncOccurrences
2022-07-22 20:00:47 -05:00
Ed Page
24735e3a1d fix!: Pull AppSettings out of API
Part of #3021
2022-07-22 16:05:54 -05:00
Ed Page
f10809f0cc fix!: Remove possible_values 2022-07-21 15:54:26 -05:00
Ed Page
fbd6e19f05 fix(complete)!: Remove deprecated Shell::possible_values 2022-07-21 15:40:40 -05:00
Ed Page
ff0796b014 fix(derive)!: Remove old derive names 2022-07-21 12:57:12 -05:00
Ed Page
6286339f81 docs(complete): Make example consistent
Fixes #3883
2022-07-11 15:20:45 -05:00
Ed Page
b4a1362486 chore: Release 2022-06-28 08:04:18 -05:00
Ed Page
5ba41d775c docs(license): Update years/holders
Without copyright assignment, everyone owns their own copyright, so
tried to reflect that.

See #3875
2022-06-27 12:55:09 -05:00
Ed Page
3823df9bbe chore: Release 2022-06-21 09:32:04 -05:00
Ed Page
ae78f88d48
Merge pull request #3852 from epage/msrv
chore: Bump MSRV from 1.56.0 to 1.56.1
2022-06-17 09:23:06 -05:00
Ed Page
82d70d82c4 chore: Bump MSRV from 1.56.0 to 1.56.1
Being a patch release, I'm fine doing this outside of a minor release.
This avoids us having to deal with indexmap having a higher MSRV.
2022-06-17 09:01:45 -05:00
Tshepang Mbambo
806f634bfa chore: trim Cargo manifest fields whose values are defaults
See...
- https://doc.rust-lang.org/cargo/reference/manifest.html?#the-documentation-field
- https://doc.rust-lang.org/cargo/reference/manifest.html?#the-readme-field
2022-06-17 15:49:04 +02:00
Ed Page
ea3bd55993 test(complete): Ensure we infer path completions from value_parser
Looks like I forgot to add a test case for this.

I put this in `clap_complete` because I expect `ValueHint` to move here
as we move towards a plugin system.

Fixes #3840
2022-06-16 09:59:30 -05:00
Ed Page
650a29c18b chore: Release 2022-06-13 09:37:47 -05:00
Ed Page
4e56acffce chore: Release 2022-06-13 09:31:29 -05:00
Ed Page
9e38353442 fix(derive): Clarify ArgEnum as ValueEnum
We aren't enumerating arguments but values for an argument, so the name
should reflect that.

This will be important as part of #1807 when we have more specific
attribute names.
2022-06-08 11:14:09 -05:00
Ed Page
14a62e11fd fix(parser): Deprecate multiple_occurrences
Fixes #3772
2022-06-08 09:54:23 -05:00
Ed Page
86a162d1bb fix(parser): Deprecate occurrences_of
This mostly exist for
- Knowing of the value came from the command-line but we now have
  `ArgMatches::source`
- Counting the number of flags but we now have `ArgAction::Count`
2022-06-07 13:30:32 -05:00
Ed Page
a712adefcd fix(parser): Deprecate value_of and friends 2022-05-25 12:57:11 -05:00
Ed Page
256643f8d3 fix: Deprecate possible_values 2022-05-25 12:57:11 -05:00
Ed Page
177511dab1 fix: Deprecate validator / validator_os
`validator_regex` is being ignored for now as I await on a comment
period for #3743
2022-05-25 12:57:11 -05:00
Ed Page
852a1b15d4 fix(help): Show value_parser's PossibleValues 2022-05-20 19:59:36 -05:00
Ed Page
2abb6804d3 fix: Switch to 2021 edition 2022-05-18 10:35:30 -05:00
Ed Page
d827364ea9 style: Normalize manifests 2022-05-18 10:33:37 -05:00
Ed Page
272334b26a fix: List rust-version for all crates 2022-05-18 10:08:10 -05:00
Ed Page
0033bf60c1 style: Address clippy complaints 2022-05-17 14:11:04 -05:00
Ed Page
f3d8ef248f feat(complete): Complete value_parser possible values 2022-05-16 15:08:47 -05:00
Ed Page
95698a4f31 chore: Release 2022-05-06 09:39:24 -05:00
Ed Page
3984e55363 docs(complete): Update changelog 2022-05-06 09:39:15 -05:00
Ed Page
b266e6d35d fix(complete): Complete visible, rather than hidden, values
In a refactor for #3503, one of the checks for `is_hide_set` got flipped
and we are completing hidden `PossibleValue`s rather than visible.

Fixes #3697
2022-05-06 09:14:32 -05:00
Ed Page
d3e36b1c90 fix(v4): Disallow leading dashes in long's
This is a step towards #3309.  We want to make longs and long aliases
more consistent in how they handle leading dashes.  There is more
flexibility offered in not stripping and it matches the v3 short
behavior of only taking the non-dash form.  This starts the process by
disallowing it completely so people will catch problems with it and
remove their existing leading dashes.  In a subsequent breaking release
we can remove the debug assert and allow triple-leading dashes.
2022-05-04 15:38:08 -05:00
Ed Page
0ecb6f4869 fix(builder): Fully recurse when building
Besides addressing the panic from assuming things were built when they
weren't, this should fix some completion issues for some people.

Fixes #3669
2022-04-30 20:02:06 -05:00
Ed Page
3ca1b77094 chore: Fix manifest 2022-04-30 06:37:57 -05:00
Ed Page
b01256be36 chore: Release 2022-04-30 06:36:33 -05:00
Ed Page
0c5400dadb chore: Release 2022-04-30 06:35:57 -05:00
Ed Page
09d21f4005 docs: Update changelog 2022-04-30 06:35:38 -05:00
Ed Page
1922b892ae fix(complete): Correctly detect positionals 2022-04-27 15:53:02 -05:00
Ed Page
53ae382c99 feat(complete): Add debug aids 2022-04-27 15:49:58 -05:00
Ed Page
4b9dd3fbbb test(complete): Cover long flags 2022-04-27 15:49:58 -05:00
Ed Page
c9b6d62ba7 test(complete): Cover subcommands 2022-04-27 15:49:58 -05:00
Ed Page
ca4439a93a fix(complete): Make short flags additive 2022-04-27 15:49:58 -05:00
Ed Page
f4892848da fix(complete): Allow subcommands in escaped arguments 2022-04-27 15:49:58 -05:00