Commit graph

189 commits

Author SHA1 Message Date
Ed Page
889ca7a537 chore: Bump versions for 4.1 2023-01-13 09:24:37 -06:00
Ed Page
a41ca2edb0 docs: Update changelog 2023-01-13 07:13:28 -06: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
fa02111092 chore: Switch to workspace inheritance 2023-01-09 12:35:54 -06:00
Ed Page
f25fe5b3e0 chore: Bump MSRV to 1.64.0 2023-01-09 12:29:41 -06:00
Ed Page
c2efb60a5f fix(error): Lowercase the start of error messages
This matches the rustc error style
2023-01-03 13:17:46 -06: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
renovate[bot]
acfc493a35
chore(deps): update compatible (dev) 2023-01-01 02:25:24 +00:00
Ed Page
0eccd556ac chore: Release 2022-12-22 12:40:15 -06:00
renovate[bot]
9b2b718df6
chore(deps): update dev 2022-12-01 21:38:13 +00:00
Ed Page
3262016c26 chore: Release 2022-11-24 11:40:15 -06:00
Ed Page
623ccbc152 style: Make clippy happy 2022-11-24 08:05:21 -06:00
Hugo Osvaldo Barrera
d169849330 docs: Clarify mention of example elsewhere
This points to "the example above", but there's no example above when
this gets rendered in docs.rs:

    https://docs.rs/clap_complete/latest/clap_complete/generator/fn.generate.html

I suppose this reference is just stale since moving docs from a single
markdown file or something similar.
2022-11-19 12:22:37 +01:00
Ed Page
c75b81eeb8 chore: Release 2022-11-07 07:39:49 -06:00
Ed Page
28324d8df7 docs: Update changelog 2022-11-07 07:39:36 -06:00
Ed Page
571f45080e
Merge pull request #4447 from tmccombs/guess-shell
Add support for determining current shell from environment
2022-11-07 07:38:51 -06:00
Ed Page
b4b94af0f8 chore: Release 2022-11-07 06:24:02 -06:00
Thayne McCombs
86db119153 feat(complete): Support getting shell from env
Add functions for getting the Shell from a path and for getting the
current shell form environment variables.

Closes: #4446
2022-11-06 23:39:55 -07:00
Ed Page
a24fb589eb chore: Update trycmd 2022-11-04 10:27:57 -05:00
Ed Page
996636d56f chore: Release 2022-10-18 14:37:53 -05:00
Ed Page
3e23cd102f fix: Require release versions of clap 2022-10-18 14:36:44 -05:00
dependabot[bot]
f0d971562a
chore(deps): bump snapbox from 0.3.3 to 0.4.0
Bumps [snapbox](https://github.com/assert-rs/trycmd) from 0.3.3 to 0.4.0.
- [Release notes](https://github.com/assert-rs/trycmd/releases)
- [Changelog](https://github.com/assert-rs/trycmd/blob/main/CHANGELOG.md)
- [Commits](https://github.com/assert-rs/trycmd/compare/snapbox-v0.3.3...snapbox-v0.4.0)

---
updated-dependencies:
- dependency-name: snapbox
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-01 18:58:27 +00:00
Ed Page
eeafb2574b docs(complete): Don't use deprecated API 2022-09-29 16:11:03 -05:00
Ed Page
80fb67edaa chore: Release 2022-09-29 12:08:47 -05:00
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