Commit graph

63 commits

Author SHA1 Message Date
Alexis (Poliorcetics) Bourget
e782775229 fix(complete): Handle newlines in command/arg descriptions
Found while trying to add Nushell completions to
[`jj`](https://github.com/martinvonz/jj).
2024-02-16 16:17:22 -06:00
Ed Page
fba7c8597b test(complete): Show newline issue 2024-02-16 16:16:36 -06:00
sudotac
1edffb8576 fix(complete): Prevent filenames splitting
Fix #5313
2024-02-02 23:31:03 +09:00
Ed Page
646134a9a9
Merge pull request #5240 from sudotac/improve-bash-completion-with-compopt
Improve bash completion with compopt
2024-01-22 09:44:11 -06:00
sudotac
13a79804c9 fix(complete): Suppress a useless space completion 2024-01-20 21:29:51 +09:00
sudotac
e25b1abddf feat(complete): Add DirPath support in bash 2024-01-20 21:29:50 +09:00
sudotac
3a222def22 fix(complete): Fix path completion in bash
Fix #5239
2024-01-20 21:29:06 +09:00
Sebastian Holmin
ba378e635c fix(complete): Use bin_name for subcommands
Bash completions for subcommands used package
name, which broke completions when the `bin_name`
was different.

Update the `custom_bin_name` test to reflect the
correct behavior.
2024-01-19 10:27:36 +01:00
Sebastian Holmin
6411995641 test(complete): Add custom bin name test 2024-01-19 10:26:26 +01:00
Ed Page
6fcba9821d fix(complete): Don't provide help output for user
We shouldn't be injecting help when being flattened.

Unsure why this made tests fail inconsistentkly between CI and local
2024-01-15 12:51:45 -06:00
Henry Hsieh
2b48858ba8 fix: Skip nosort option below bash 4.4 2024-01-02 21:14:20 +08:00
Ed Page
29208083b0 test: Update snapshots 2023-12-27 12:09:15 -06:00
jporwal05
34291a2b46 fix: (fish-completion) Help for value enum
Resolves #5101

- The completion of value enums now displays accurate help text
- This fix encloses help text in single quotes
- Any text after tab is taken as help text
- Comma in help text is not escaped
- This is because the the help text is now treated as literal
- No variable expansion or command substitution in help text
2023-09-07 17:54:28 +05:30
jporwal05
ca06c321c5 test: (completion) enum value help
- Breaking for fish shell
- Matching the bad output to make the test pass
2023-09-07 17:19:43 +05:30
Roland Fredenhagen
5b10a9d83c
test(complete): Test help escaping 2023-08-04 01:20:50 +07:00
Roland Fredenhagen
4f9cf6be20
feat(complete): Dynamic fish completions 2023-08-01 01:42:05 +07:00
Ed Page
12e1877627 fix(complete): Fix bash dynamic completions 2023-07-28 14:10:22 -05:00
Ed Page
56afdabcc0 test(complete): Rename fixture to avoid ambiguity 2023-07-28 13:54:02 -05:00
Ed Page
dc953e95d0 test(complete): Register bash dynamic completions 2023-07-28 13:28:30 -05:00
Roland Fredenhagen
9a6208c795 test(complete): Allow E2E dynamic completion tests 2023-07-28 12:55:57 -05:00
Ed Page
fa95531230 test(complete): Make room for alt completion styles 2023-07-28 12:48:36 -05:00
Roland Fredenhagen
ab1407f1ae
chore: Fix dynamic completion tests 2023-07-26 23:52:14 +07:00
Ed Page
f98ba908aa chore(complete): Update completest 2023-07-24 12:57:56 -05:00
Ed Page
51e37af365 test(complete): Add basic tests for all shells 2023-07-20 20:08:58 -05:00
Ed Page
28be38b3a7 refactor(complete): Split tests up
This makes them easier to read and and easier to manually invoke
2023-07-20 20:06:08 -05:00
Ed Page
010d7c5464 test(complete): First end-to-end test 2023-07-20 20:06:01 -05:00
Ed Page
35a9d8438e fix(complete): Prefer our own sort order
For testing, I'm seeing different sort orders for local and CI despite
using the same bash version...
2023-07-20 12:14:24 -05:00
RubixDev
7b5bc6640c
fix(complete): PS short options not case-sensitive
fixes #2145
2023-07-04 15:27:47 +08:00
clubby789
b1b2231db2 fix: Don't emit catchall when we have subcommands 2023-05-10 19:44:02 +01:00
clubby789
2f97216156 fix: Respect ValueHint::Other in bash 2023-05-09 20:11:48 +01:00
Huan-Cheng Chang
a379bae895 fix: Escape special characters properly for zsh
Signed-off-by: Huan-Cheng Chang <changhc84@gmail.com>
2023-04-20 21:52:36 +02:00
XiaoXiaoSN
0f3e729358 feat(complete): Support to run ZSH completion as a script 2023-02-27 23:23:50 +08:00
Ed Page
cdb33b6ad2 test(complete): Adjust bash snapshot 2023-02-24 07:40:24 -06:00
Ed Page
77803337f8
Merge pull request #4612 from davvid/zsh-multi-length-arguments
clap_complete: fix support for two multi-length arguments in zsh
2023-02-23 11:55:17 -06:00
Fredrik Jansson
3426310d8e fix: Bash test cases 2023-01-23 19:20:09 +01:00
David Aguilar
170bd59111 fix(complete): Handle multi-valued arguments
zsh completions for commands that have multiple Vec arguments require
special care.

We can have two Vec args separated with a value terminator.
We can also have two Vec args with no value terminators specified
where the final arg uses 'raw' and thus requires '--' to be used.

The 2nd of these scenarios requires special handling to avoid
emitting a duplicate '*:arguments' completion entry.

Currently, the zsh completions generate an error in this scenario:

    $ my-app <TAB>
    _arguments:...: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

We already use the '-S' option when calling _arguments.
This option makes it so that completion stops after '--' is encountered.
This means that the handling for trailing 'raw' arguments does not need
to specified.

Special-case multi-valued arguments so that we can skip emitting
the final multi-valued argument if a previous multi-valued argument
has already been emitted.

Closes #3022
Signed-off-by: David Aguilar <davvid@gmail.com>
2023-01-10 14:39:33 -08:00
David Aguilar
58b0c504d8 fix(complete): Emit value terminators on zsh
Emit the user-defined value terminator into the zsh completion pattern
to avoid doubled rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

https://github.com/clap-rs/clap/issues/3266#issuecomment-1007901407
noted that including the value terminator is one step towards a
robust solution for handling multiple multi-valued arguments.

This change does not yet handle automatically detecting when a value
terminator is needed, but it does add tests to ensure that
user-specified value terminators are used on zsh.

Related-to: #3022
Signed-off-by: David Aguilar <davvid@gmail.com>
2023-01-10 00:59:25 -08:00
Ed Page
36bc641648 fix(help): Remove extraneous text from built-ins
This is an intermediate solution for #4408.  As there were no agreeed
upon goals, I went with what I felt read well and that I saw commonly
used on non-clap commands.

- "information" isn't really a necessary word.
- I originally favored `Print this help` but realied that doesn't read
  correctly in completions.
- Besides being shorter, the reason for the flipped short/long hint is
  it gives people the context they need for scanning, emphasizing
  "summary" and "more".

Fixes #4409
2023-01-03 11:02:26 -06: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
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
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