Commit graph

53 commits

Author SHA1 Message Date
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
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
Marti Raudsepp
89cae3a2b3 fix(complete): Fix handling of multiple arguments 2022-09-28 23:02:31 +03: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
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
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
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
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
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
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
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
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
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
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
14a62e11fd fix(parser): Deprecate multiple_occurrences
Fixes #3772
2022-06-08 09:54:23 -05:00
Ed Page
256643f8d3 fix: Deprecate possible_values 2022-05-25 12:57:11 -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
1922b892ae fix(complete): Correctly detect positionals 2022-04-27 15:53:02 -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
9f9e410c6d feat(complete): Minimal rust-completion
Inspired by argcomplete, this provides Rust-implemented completions
- Only bash for now
- No subcommand support
- No flag value support
- No special settings support
- No handling of positions within positionals
- No prioritizing of required or removing of conflicts (including
  self-conflicts)
2022-04-27 15:49:58 -05:00
Ed Page
3d64ebacac test(complete): Option to verify examples 2022-04-27 09:03:47 -05:00
Ed Page
55bfacbf43 test(complete): Use official extensions for snapshots 2022-04-22 16:21:10 -05:00
Federico Ciardi
5689adc875 fix(clap_complete_fig): Correct requiresEquals name and add it to the right objects 2022-03-18 14:46:20 +01:00
Federico Ciardi
abc72a7d0b feat(clap_complete_fig): Add exclusiveOn and isRepeatable 2022-03-17 21:47:18 +01:00
Federico Ciardi
f755198349
feat(clap_complete_fig): support hide and require_equals (#3560) 2022-03-17 20:35:52 +00:00
Ed Page
02fe7659c0 test(complete): Switch to snapshot testing
- This will make it easier to update
- We now uniformly test each shell
2022-03-07 14:03:49 -06:00
Ed Page
e8010e79a9 refactor: Update app variables to cmd 2022-02-14 15:55:56 -06:00
Ed Page
c4144d7d6c docs: Update App references to Command 2022-02-14 15:33:49 -06:00
Gibson Fahnestock
6f36ca3a25
fix(complete): escape fish possible values
Fixes: https://github.com/clap-rs/clap/issues/3467
2022-02-14 20:58:57 +00:00
Gibson Fahnestock
0fbabaa3fe
test(completion): add regression test for fish quoting issue 2022-02-14 20:55:06 +00:00
Ed Page
272f840178 feat: Replace core set of AppSettings with functions
This is a part of #2717

Some settings didn't get getters because
- They are transient parse settings (e.g. ignore errors)
- They get propagated to args and should be checked there

`is_allow_hyphen_values_set` is a curious case.  In some cases, we only
check the app and not an arg.  This seems suspicious.
2022-02-11 12:35:09 -06:00
Haim Ashkenazi
c90a48bf0b More failing tests, hope this will end it :( 2022-02-05 17:16:40 +02:00
Haim Ashkenazi
3c2cea9754 Fixed failing test 2022-02-05 17:09:06 +02:00
Ed Page
4a43b51a42 fix(complete): Handle help completions
The main motivation was to reduce special cases by putting all of the
logic in one place.
2022-01-17 09:23:04 -06:00
Clifton King
658b7a0841 fix(complete): Fix unescaped single quotes in zsh
help strings for subcomand args did not escape single quotes
2022-01-15 14:33:11 -06:00
cherryblossom
6d27488602
fix(complete): Use Elvish v0.17 lambda syntax
[Elvish v0.17][1] deprecated the old lambda syntax (`[arg1 arg2] { body }`)
in favour of the new `{|arg1 arg2| body }` syntax. This commit uses the
new syntax to stop deprecation warnings.

[1]: https://elv.sh/blog/0.17.0-release-notes.html#deprecated-features
2022-01-12 11:58:18 +11:00