Skip to content

Commit

Permalink
completion: add value_terminator to workaround clap-rs/clap#3022
Browse files Browse the repository at this point in the history
Now that clap-rs/clap#4624 was merged we can use value_terminator to fix the
zsh completions for commands that use two consecutive multi-valued arguments.

A more complete solution may arrive in clap-rs/clap#4612 but until that is
merged we can use this solution for now. If that change is ever merged then
we can bump our clap_complete version and remove our use of value_terminator.

Related-to: #10
Related-to: clap-rs/clap#3022
Related-to: clap-rs/clap#4624
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Jan 20, 2023
1 parent a1e2db7 commit e6a471c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 1 addition & 4 deletions doc/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,12 @@ zsh shell completion script.

```bash
mkdir -p ~/.config/zsh/completion
garden completion zsh |
grep -v \*::arguments >~/.config/zsh/completion/_garden
garden completion zsh >~/.config/zsh/completion/_garden
```

Use `garden completion --commands zsh` instead of `garden completion zsh`
to include completions for custom commands.

The `grep` filter is needed to workaround [clap #3022](https://github.com/clap-rs/clap/issues/3022).

*NOTE*: You should regenerate the `_garden` zsh completion script whenever `garden`
is upgraded to ensure that all of the options and commands have up to date completions.

Expand Down
7 changes: 6 additions & 1 deletion src/cmds/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub struct CmdOptions {
/// Tree query for the gardens, groups or trees to execute commands within
query: String,
/// Custom commands to run over the resolved trees
#[arg(required = true)]
// NOTE: value_terminator may not be needed in future versions of clap_complete.
// https://github.com/clap-rs/clap/pull/4612
#[arg(required = true, value_terminator = "--")]
commands: Vec<String>,
/// Arguments to forward to custom commands
#[arg(last = true)]
Expand All @@ -55,6 +57,9 @@ pub struct CustomOptions {
#[arg(long, short)]
no_errexit: bool,
/// Tree queries for the Gardens/Groups/Trees to execute commands within
// NOTE: value_terminator may not be needed in future versions of clap_complete.
// https://github.com/clap-rs/clap/pull/4612
#[arg(value_terminator = "--")]
queries: Vec<String>,
/// Arguments to forward to custom commands
#[arg(last = true)]
Expand Down
3 changes: 3 additions & 0 deletions src/cmds/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub fn main(options: &MainOptions, completion_options: &CompletionOptions) -> Re
)
.arg(
Arg::new("queries")
// NOTE: value_terminator may not be needed in future versions of clap_complete.
// https://github.com/clap-rs/clap/pull/4612
.value_terminator("--")
.help("Tree queries to find trees where commands will be run"),
)
.arg(
Expand Down

0 comments on commit e6a471c

Please sign in to comment.