Repository: clap-rs/clap
Pull request #4625 (2023-01-11 01:51:07)

fix(doc): Fix typos in document of `ArgMatches` methods
<!--
Thanks for helping out!

Please link the appropriate issue from your PR.

If you don't have an issue, we'd recommend starting with one first so the PR can focus on the
implementation (unless its an obvious bug or documentation fix that will have
little conversation).
-->
While reading API documents, I found these typos.



Patch:
diff --git a/clap_complete/src/shells/zsh.rs b/clap_complete/src/shells/zsh.rs
index 15a9ed12..580de77a 100644
--- a/clap_complete/src/shells/zsh.rs
+++ b/clap_complete/src/shells/zsh.rs
@@ -626,15 +626,8 @@ fn write_positionals_of(p: &Command) -> String {
         debug!("write_positionals_of:iter: arg={}", arg.get_id());
 
         let num_args = arg.get_num_args().expect("built");
-        let cardinality_value;
         let cardinality = if num_args.max_values() > 1 {
-            match arg.get_value_terminator() {
-                Some(terminator) => {
-                    cardinality_value = format!("*{}:", escape_value(terminator));
-                    cardinality_value.as_str()
-                }
-                None => "*:",
-            }
+            "*:"
         } else if !arg.is_required_set() {
             ":"
         } else {
diff --git a/src/builder/arg.rs b/src/builder/arg.rs
index bea0807f..53f68075 100644
--- a/src/builder/arg.rs
+++ b/src/builder/arg.rs
@@ -3858,13 +3858,6 @@ impl Arg {
         self.val_delim
     }
 
-    /// Get the value terminator for this argument. The value_terminator is a value
-    /// that terminates parsing of multi-valued arguments.
-    #[inline]
-    pub fn get_value_terminator(&self) -> Option<&Str> {
-        self.terminator.as_ref()
-    }
-
     /// Get the index of this argument, if any
     #[inline]
     pub fn get_index(&self) -> Option<usize> {
diff --git a/src/parser/matches/arg_matches.rs b/src/parser/matches/arg_matches.rs
index 000ee77d..b08d9716 100644
--- a/src/parser/matches/arg_matches.rs
+++ b/src/parser/matches/arg_matches.rs
@@ -476,7 +476,7 @@ impl ArgMatches {
     ///
     /// # Panics
     ///
-    /// If `id` is is not a valid argument or group name.  To handle this case programmatically, see
+    /// If `id` is not a valid argument or group name.  To handle this case programmatically, see
     /// [`ArgMatches::try_contains_id`].
     ///
     /// # Examples
@@ -602,7 +602,7 @@ impl ArgMatches {
     ///
     /// # Panics
     ///
-    /// If `id` is is not a valid argument or group id.
+    /// If `id` is not a valid argument or group id.
     ///
     /// # Examples
     ///
@@ -648,7 +648,7 @@ impl ArgMatches {
     ///
     /// # Panics
     ///
-    /// If `id` is is not a valid argument or group id.
+    /// If `id` is not a valid argument or group id.
     ///
     /// # Examples
     ///
@@ -791,7 +791,7 @@ impl ArgMatches {
     ///
     /// # Panics
     ///
-    /// If `id` is is not a valid argument or group id.
+    /// If `id` is not a valid argument or group id.
     ///
     /// # Examples
     ///
@@ -988,7 +988,7 @@ impl ArgMatches {
     ///
     /// # Panics
     ///
-    /// If `id` is is not a valid subcommand.
+    /// If `id` is not a valid subcommand.
     ///
     /// # Examples
     ///


Test patch:
diff --git a/clap_complete/tests/bash.rs b/clap_complete/tests/bash.rs
index d01651f2..a3e454de 100644
--- a/clap_complete/tests/bash.rs
+++ b/clap_complete/tests/bash.rs
@@ -84,18 +84,6 @@ fn value_hint() {
     );
 }
 
-#[test]
-fn value_terminator() {
-    let name = "my-app";
-    let cmd = common::value_terminator_command(name);
-    common::assert_matches_path(
-        "tests/snapshots/value_terminator.bash",
-        clap_complete::shells::Bash,
-        cmd,
-        name,
-    );
-}
-
 #[cfg(feature = "unstable-dynamic")]
 #[test]
 fn register_minimal() {
diff --git a/clap_complete/tests/common.rs b/clap_complete/tests/common.rs
index 3f8cb437..ab52fe93 100644
--- a/clap_complete/tests/common.rs
+++ b/clap_complete/tests/common.rs
@@ -252,15 +252,6 @@ pub fn value_hint_command(name: &'static str) -> clap::Command {
         )
 }
 
-pub fn value_terminator_command(name: &'static str) -> clap::Command {
-    clap::Command::new(name).arg(
-        clap::Arg::new("arguments")
-            .help("multi-valued argument with a value terminator")
-            .num_args(1..)
-            .value_terminator(";"),
-    )
-}
-
 pub fn assert_matches_path(
     expected_path: impl AsRef<std::path::Path>,
     gen: impl clap_complete::Generator,
diff --git a/clap_complete/tests/elvish.rs b/clap_complete/tests/elvish.rs
index 26075a67..76beb983 100644
--- a/clap_complete/tests/elvish.rs
+++ b/clap_complete/tests/elvish.rs
@@ -83,15 +83,3 @@ fn value_hint() {
         name,
     );
 }
-
-#[test]
-fn value_terminator() {
-    let name = "my-app";
-    let cmd = common::value_terminator_command(name);
-    common::assert_matches_path(
-        "tests/snapshots/value_terminator.elvish",
-        clap_complete::shells::Elvish,
-        cmd,
-        name,
-    );
-}
diff --git a/clap_complete/tests/fish.rs b/clap_complete/tests/fish.rs
index 9393ed69..92c1c4a4 100644
--- a/clap_complete/tests/fish.rs
+++ b/clap_complete/tests/fish.rs
@@ -83,15 +83,3 @@ fn value_hint() {
         name,
     );
 }
-
-#[test]
-fn value_terminator() {
-    let name = "my-app";
-    let cmd = common::value_terminator_command(name);
-    common::assert_matches_path(
-        "tests/snapshots/value_terminator.fish",
-        clap_complete::shells::Fish,
-        cmd,
-        name,
-    );
-}
diff --git a/clap_complete/tests/powershell.rs b/clap_complete/tests/powershell.rs
index 1f18618b..fa6657d3 100644
--- a/clap_complete/tests/powershell.rs
+++ b/clap_complete/tests/powershell.rs
@@ -83,15 +83,3 @@ fn value_hint() {
         name,
     );
 }
-
-#[test]
-fn value_terminator() {
-    let name = "my-app";
-    let cmd = common::value_terminator_command(name);
-    common::assert_matches_path(
-        "tests/snapshots/value_terminator.ps1",
-        clap_complete::shells::PowerShell,
-        cmd,
-        name,
-    );
-}
diff --git a/clap_complete/tests/snapshots/value_terminator.bash b/clap_complete/tests/snapshots/value_terminator.bash
deleted file mode 100644
index 3b4bc730..00000000
--- a/clap_complete/tests/snapshots/value_terminator.bash
+++ /dev/null
@@ -1,38 +0,0 @@
-_my-app() {
-    local i cur prev opts cmds
-    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"
-                ;;
-            *)
-                ;;
-        esac
-    done
-
-    case "${cmd}" in
-        my__app)
-            opts="-h --help [arguments]..."
-            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
-            ;;
-    esac
-}
-
-complete -F _my-app -o bashdefault -o default my-app
diff --git a/clap_complete/tests/snapshots/value_terminator.elvish b/clap_complete/tests/snapshots/value_terminator.elvish
deleted file mode 100644
index 89b26e00..00000000
--- a/clap_complete/tests/snapshots/value_terminator.elvish
+++ /dev/null
@@ -1,26 +0,0 @@
-
-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'
-        }
-    ]
-    $completions[$command]
-}
diff --git a/clap_complete/tests/snapshots/value_terminator.fish b/clap_complete/tests/snapshots/value_terminator.fish
deleted file mode 100644
index a33c671a..00000000
--- a/clap_complete/tests/snapshots/value_terminator.fish
+++ /dev/null
@@ -1,1 +0,0 @@
-complete -c my-app -s h -l help -d 'Print help'
diff --git a/clap_complete/tests/snapshots/value_terminator.ps1 b/clap_complete/tests/snapshots/value_terminator.ps1
deleted file mode 100644
index 30262afe..00000000
--- a/clap_complete/tests/snapshots/value_terminator.ps1
+++ /dev/null
@@ -1,32 +0,0 @@
-
-using namespace System.Management.Automation
-using namespace System.Management.Automation.Language
-
-Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
-    param($wordToComplete, $commandAst, $cursorPosition)
-
-    $commandElements = $commandAst.CommandElements
-    $command = @(
-        'my-app'
-        for ($i = 1; $i -lt $commandElements.Count; $i++) {
-            $element = $commandElements[$i]
-            if ($element -isnot [StringConstantExpressionAst] -or
-                $element.StringConstantType -ne [StringConstantType]::BareWord -or
-                $element.Value.StartsWith('-') -or
-                $element.Value -eq $wordToComplete) {
-                break
-        }
-        $element.Value
-    }) -join ';'
-
-    $completions = @(switch ($command) {
-        'my-app' {
-            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
-            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
-            break
-        }
-    })
-
-    $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
-        Sort-Object -Property ListItemText
-}
diff --git a/clap_complete/tests/snapshots/value_terminator.zsh b/clap_complete/tests/snapshots/value_terminator.zsh
deleted file mode 100644
index 656d8ea1..00000000
--- a/clap_complete/tests/snapshots/value_terminator.zsh
+++ /dev/null
@@ -1,30 +0,0 @@
-#compdef my-app
-
-autoload -U is-at-least
-
-_my-app() {
-    typeset -A opt_args
-    typeset -a _arguments_options
-    local ret=1
-
-    if is-at-least 5.2; then
-        _arguments_options=(-s -S -C)
-    else
-        _arguments_options=(-s -C)
-    fi
-
-    local context curcontext="$curcontext" state line
-    _arguments "${_arguments_options[@]}" \
-'-h[Print help]' \
-'--help[Print help]' \
-'*;::arguments -- multi-valued argument with a value terminator:' \
-&& ret=0
-}
-
-(( $+functions[_my-app_commands] )) ||
-_my-app_commands() {
-    local commands; commands=()
-    _describe -t commands 'my-app commands' commands "$@"
-}
-
-_my-app "$@"
diff --git a/clap_complete/tests/zsh.rs b/clap_complete/tests/zsh.rs
index 57040bde..df6a2778 100644
--- a/clap_complete/tests/zsh.rs
+++ b/clap_complete/tests/zsh.rs
@@ -83,15 +83,3 @@ fn value_hint() {
         name,
     );
 }
-
-#[test]
-fn value_terminator() {
-    let name = "my-app";
-    let cmd = common::value_terminator_command(name);
-    common::assert_matches_path(
-        "tests/snapshots/value_terminator.zsh",
-        clap_complete::shells::Zsh,
-        cmd,
-        name,
-    );
-}