Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: clap-rs/clap
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: clap_complete-v4.2.2
Choose a base ref
...
head repository: clap-rs/clap
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: clap_complete-v4.2.3
Choose a head ref
  • 4 commits
  • 16 files changed
  • 2 contributors

Commits on May 10, 2023

  1. Copy the full SHA
    b1b2231 View commit details

Commits on May 12, 2023

  1. Merge pull request #4899 from clubby789/zsh-subcommand-catchall

    fix: (complete, zsh) Don't emit catchall when we have subcommands
    epage authored May 12, 2023
    Copy the full SHA
    2fd3e4c View commit details
  2. docs: Update changelog

    epage committed May 12, 2023
    Copy the full SHA
    9d0e451 View commit details
  3. chore: Release

    epage committed May 12, 2023
    Copy the full SHA
    36f7928 View commit details
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion clap_complete/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased] - ReleaseDate

## [4.2.3] - 2023-05-12

### Fixes

- *(zsh)* Avoid error when mixing multiple values with subcommands

## [4.2.2] - 2023-05-09

- *(bash)* Respect `ValueHint::Other`
@@ -137,7 +143,8 @@ MSRV changed to 1.64.0
## [3.0.1] - 2022-01-03

<!-- next-url -->
[Unreleased]: https://github.com/clap-rs/clap/compare/clap_complete-v4.2.2...HEAD
[Unreleased]: https://github.com/clap-rs/clap/compare/clap_complete-v4.2.3...HEAD
[4.2.3]: https://github.com/clap-rs/clap/compare/clap_complete-v4.2.2...clap_complete-v4.2.3
[4.2.2]: https://github.com/clap-rs/clap/compare/clap_complete-v4.2.1...clap_complete-v4.2.2
[4.2.1]: https://github.com/clap-rs/clap/compare/clap_complete-v4.2.0...clap_complete-v4.2.1
[4.2.0]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.6...clap_complete-v4.2.0
2 changes: 1 addition & 1 deletion clap_complete/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clap_complete"
version = "4.2.2"
version = "4.2.3"
description = "Generate shell completion scripts for your clap::Command"
repository = "https://github.com/clap-rs/clap/tree/master/clap_complete"
categories = ["command-line-interface"]
8 changes: 4 additions & 4 deletions clap_complete/README.md
Original file line number Diff line number Diff line change
@@ -5,16 +5,16 @@
[![Crates.io](https://img.shields.io/crates/v/clap_complete?style=flat-square)](https://crates.io/crates/clap_complete)
[![Crates.io](https://img.shields.io/crates/d/clap_complete?style=flat-square)](https://crates.io/crates/clap_complete)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.2/LICENSE-APACHE)
[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.2/LICENSE-MIT)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.3/LICENSE-APACHE)
[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.3/LICENSE-MIT)

Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).

1. [About](#about)
2. [API Reference](https://docs.rs/clap_complete)
3. [Questions & Discussions](https://github.com/clap-rs/clap/discussions)
4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.2/clap_complete/CONTRIBUTING.md)
5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.2/README.md#sponsors)
4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.3/clap_complete/CONTRIBUTING.md)
5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_complete-v4.2.3/README.md#sponsors)

## About

4 changes: 3 additions & 1 deletion clap_complete/src/shells/zsh.rs
Original file line number Diff line number Diff line change
@@ -624,7 +624,9 @@ fn write_positionals_of(p: &Command) -> String {
}

let cardinality_value;
let cardinality = if is_multi_valued {
// If we have any subcommands, we'll emit a catch-all argument, so we shouldn't
// emit one here.
let cardinality = if is_multi_valued && !p.has_subcommands() {
match arg.get_value_terminator() {
Some(terminator) => {
cardinality_value = format!("*{}:", escape_value(terminator));
12 changes: 12 additions & 0 deletions clap_complete/tests/bash.rs
Original file line number Diff line number Diff line change
@@ -123,3 +123,15 @@ fn two_multi_valued_arguments() {
name,
);
}

#[test]
fn subcommand_last() {
let name = "my-app";
let cmd = common::subcommand_last(name);
common::assert_matches_path(
"tests/snapshots/subcommand_last.bash",
clap_complete::shells::Bash,
cmd,
name,
);
}
6 changes: 6 additions & 0 deletions clap_complete/tests/common.rs
Original file line number Diff line number Diff line change
@@ -275,6 +275,12 @@ pub fn two_multi_valued_arguments_command(name: &'static str) -> clap::Command {
)
}

pub fn subcommand_last(name: &'static str) -> clap::Command {
clap::Command::new(name)
.arg(clap::Arg::new("free").last(true))
.subcommands([clap::Command::new("foo"), clap::Command::new("bar")])
}

pub fn assert_matches_path(
expected_path: impl AsRef<std::path::Path>,
gen: impl clap_complete::Generator,
12 changes: 12 additions & 0 deletions clap_complete/tests/elvish.rs
Original file line number Diff line number Diff line change
@@ -107,3 +107,15 @@ fn two_multi_valued_arguments() {
name,
);
}

#[test]
fn subcommand_last() {
let name = "my-app";
let cmd = common::subcommand_last(name);
common::assert_matches_path(
"tests/snapshots/subcommand_last.elvish",
clap_complete::shells::Elvish,
cmd,
name,
);
}
12 changes: 12 additions & 0 deletions clap_complete/tests/fish.rs
Original file line number Diff line number Diff line change
@@ -107,3 +107,15 @@ fn two_multi_valued_arguments() {
name,
);
}

#[test]
fn subcommand_last() {
let name = "my-app";
let cmd = common::subcommand_last(name);
common::assert_matches_path(
"tests/snapshots/subcommand_last.fish",
clap_complete::shells::Fish,
cmd,
name,
);
}
12 changes: 12 additions & 0 deletions clap_complete/tests/powershell.rs
Original file line number Diff line number Diff line change
@@ -107,3 +107,15 @@ fn two_multi_valued_arguments() {
name,
);
}

#[test]
fn subcommand_last() {
let name = "my-app";
let cmd = common::subcommand_last(name);
common::assert_matches_path(
"tests/snapshots/subcommand_last.ps1",
clap_complete::shells::PowerShell,
cmd,
name,
);
}
140 changes: 140 additions & 0 deletions clap_complete/tests/snapshots/subcommand_last.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
_my-app() {
local i cur prev opts cmd
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmd=""
opts=""

for i in ${COMP_WORDS[@]}
do
case "${cmd},${i}" in
",$1")
cmd="my__app"
;;
my__app,bar)
cmd="my__app__bar"
;;
my__app,foo)
cmd="my__app__foo"
;;
my__app,help)
cmd="my__app__help"
;;
my__app__help,bar)
cmd="my__app__help__bar"
;;
my__app__help,foo)
cmd="my__app__help__foo"
;;
my__app__help,help)
cmd="my__app__help__help"
;;
*)
;;
esac
done

case "${cmd}" in
my__app)
opts="-h --help [free] foo bar help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
my__app__bar)
opts="-h --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
my__app__foo)
opts="-h --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
my__app__help)
opts="foo bar help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
my__app__help__bar)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
my__app__help__foo)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
my__app__help__help)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
esac
}

complete -F _my-app -o bashdefault -o default my-app
48 changes: 48 additions & 0 deletions clap_complete/tests/snapshots/subcommand_last.elvish
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

use builtin;
use str;

set edit:completion:arg-completer[my-app] = {|@words|
fn spaces {|n|
builtin:repeat $n ' ' | str:join ''
}
fn cand {|text desc|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}
var command = 'my-app'
for word $words[1..-1] {
if (str:has-prefix $word '-') {
break
}
set command = $command';'$word
}
var completions = [
&'my-app'= {
cand -h 'Print help'
cand --help 'Print help'
cand foo 'foo'
cand bar 'bar'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'my-app;foo'= {
cand -h 'Print help'
cand --help 'Print help'
}
&'my-app;bar'= {
cand -h 'Print help'
cand --help 'Print help'
}
&'my-app;help'= {
cand foo 'foo'
cand bar 'bar'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'my-app;help;foo'= {
}
&'my-app;help;bar'= {
}
&'my-app;help;help'= {
}
]
$completions[$command]
}
9 changes: 9 additions & 0 deletions clap_complete/tests/snapshots/subcommand_last.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help'
complete -c my-app -n "__fish_use_subcommand" -f -a "foo"
complete -c my-app -n "__fish_use_subcommand" -f -a "bar"
complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c my-app -n "__fish_seen_subcommand_from foo" -s h -l help -d 'Print help'
complete -c my-app -n "__fish_seen_subcommand_from bar" -s h -l help -d 'Print help'
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from foo; and not __fish_seen_subcommand_from bar; and not __fish_seen_subcommand_from help" -f -a "foo"
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from foo; and not __fish_seen_subcommand_from bar; and not __fish_seen_subcommand_from help" -f -a "bar"
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from foo; and not __fish_seen_subcommand_from bar; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
Loading