From a4b2c78ef20ab55139633ffd7ec8990fb91acd51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:58:20 +0000 Subject: [PATCH 1/2] build(deps): bump shtab from 1.5.8 to 1.7.1 in /ci/builder Bumps [shtab](https://github.com/iterative/shtab) from 1.5.8 to 1.7.1. - [Release notes](https://github.com/iterative/shtab/releases) - [Commits](https://github.com/iterative/shtab/compare/v1.5.8...v1.7.1) --- updated-dependencies: - dependency-name: shtab dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- ci/builder/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/builder/requirements.txt b/ci/builder/requirements.txt index 79611e6016499..aa2d83960c6c4 100644 --- a/ci/builder/requirements.txt +++ b/ci/builder/requirements.txt @@ -51,7 +51,7 @@ ruamel.yaml==0.18.6 ruff==0.0.292 scipy==1.14.1 semver==3.0.0 -shtab==1.5.8 +shtab==1.7.1 sqlparse==0.5.0 toml==0.10.2 twine==5.1.1 From 137a307120b38c6f549277523154149c4677a2f5 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Mon, 2 Dec 2024 08:45:05 +0000 Subject: [PATCH 2/2] Run bin/gen-completion generate --- ci/test/lint-main/checks/check-new-line.sh | 2 +- misc/completions/bash/_scratch | 70 +++++++++++++--------- misc/completions/zsh/_scratch | 30 ++++++---- 3 files changed, 62 insertions(+), 40 deletions(-) diff --git a/ci/test/lint-main/checks/check-new-line.sh b/ci/test/lint-main/checks/check-new-line.sh index 20801af950855..2c5a6b90d6236 100755 --- a/ci/test/lint-main/checks/check-new-line.sh +++ b/ci/test/lint-main/checks/check-new-line.sh @@ -22,7 +22,7 @@ files=$(git_files "$@") # Only binary files are permitted to omit a trailing newline. If you're here to # exclude a text file that is missing its trailing newline, like an SVG, add # a trailing newline to the text file instead. -newline_files=$(grep -vE '\.(png|jpe?g|pb|avro|ico|so)$' <<< "$files") +newline_files=$(grep -vE '(_scratch|\.(png|jpe?g|pb|avro|ico|so))$' <<< "$files") try xargs misc/lint/trailing-newline.sh <<< "$newline_files" try xargs git --no-pager diff --check "$(git_empty_tree)" <<< "$newline_files" diff --git a/misc/completions/bash/_scratch b/misc/completions/bash/_scratch index 435f56ab678c4..012b7bdfef9be 100644 --- a/misc/completions/bash/_scratch +++ b/misc/completions/bash/_scratch @@ -71,7 +71,7 @@ _shtab_replace_nonword() { # set default values (called for the initial parser & any subparsers) _set_parser_defaults() { local subparsers_var="${prefix}_subparsers[@]" - sub_parsers=${!subparsers_var} + sub_parsers=${!subparsers_var-} local current_option_strings_var="${prefix}_option_strings[@]" current_option_strings=${!current_option_strings_var} @@ -88,19 +88,19 @@ _set_new_action() { current_action="${prefix}_$(_shtab_replace_nonword $1)" local current_action_compgen_var=${current_action}_COMPGEN - current_action_compgen="${!current_action_compgen_var}" + current_action_compgen="${!current_action_compgen_var-}" local current_action_choices_var="${current_action}_choices[@]" - current_action_choices="${!current_action_choices_var}" + current_action_choices="${!current_action_choices_var-}" local current_action_nargs_var="${current_action}_nargs" - if [ -n "${!current_action_nargs_var}" ]; then + if [ -n "${!current_action_nargs_var-}" ]; then current_action_nargs="${!current_action_nargs_var}" else current_action_nargs=1 fi - current_action_args_start_index=$(( $word_index + 1 )) + current_action_args_start_index=$(( $word_index + 1 - $pos_only )) current_action_is_positional=$2 } @@ -114,10 +114,20 @@ _set_new_action() { # ${!x} -> ${hello} -> "world" _shtab_scratch() { local completing_word="${COMP_WORDS[COMP_CWORD]}" + local completed_positional_actions + local current_action + local current_action_args_start_index + local current_action_choices + local current_action_compgen + local current_action_is_positional + local current_action_nargs + local current_option_strings + local sub_parsers COMPREPLY=() - prefix=_shtab_scratch - word_index=0 + local prefix=_shtab_scratch + local word_index=0 + local pos_only=0 # "--" delimeter not encountered yet _set_parser_defaults word_index=1 @@ -126,26 +136,30 @@ _shtab_scratch() { while [ $word_index -ne $COMP_CWORD ]; do local this_word="${COMP_WORDS[$word_index]}" - if [[ -n $sub_parsers && " ${sub_parsers[@]} " =~ " ${this_word} " ]]; then - # valid subcommand: add it to the prefix & reset the current action - prefix="${prefix}_$(_shtab_replace_nonword $this_word)" - _set_parser_defaults - fi - - if [[ " ${current_option_strings[@]} " =~ " ${this_word} " ]]; then - # a new action should be acquired (due to recognised option string or - # no more input expected from current action); - # the next positional action can fill in here - _set_new_action $this_word false - fi - - if [[ "$current_action_nargs" != "*" ]] && \ - [[ "$current_action_nargs" != "+" ]] && \ - [[ "$current_action_nargs" != *"..." ]] && \ - (( $word_index + 1 - $current_action_args_start_index >= \ - $current_action_nargs )); then - $current_action_is_positional && let "completed_positional_actions += 1" - _set_new_action "pos_${completed_positional_actions}" true + if [[ $pos_only = 1 || " $this_word " != " -- " ]]; then + if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then + # valid subcommand: add it to the prefix & reset the current action + prefix="${prefix}_$(_shtab_replace_nonword $this_word)" + _set_parser_defaults + fi + + if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then + # a new action should be acquired (due to recognised option string or + # no more input expected from current action); + # the next positional action can fill in here + _set_new_action $this_word false + fi + + if [[ "$current_action_nargs" != "*" ]] && \ + [[ "$current_action_nargs" != "+" ]] && \ + [[ "$current_action_nargs" != *"..." ]] && \ + (( $word_index + 1 - $current_action_args_start_index - $pos_only >= \ + $current_action_nargs )); then + $current_action_is_positional && let "completed_positional_actions += 1" + _set_new_action "pos_${completed_positional_actions}" true + fi + else + pos_only=1 # "--" delimeter encountered fi let "word_index+=1" @@ -153,7 +167,7 @@ _shtab_scratch() { # Generate the completions - if [[ "${completing_word}" == -* ]]; then + if [[ $pos_only = 0 && "${completing_word}" == -* ]]; then # optional argument started: use option strings COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") ) else diff --git a/misc/completions/zsh/_scratch b/misc/completions/zsh/_scratch index a053368aba608..2e113ae62166f 100644 --- a/misc/completions/zsh/_scratch +++ b/misc/completions/zsh/_scratch @@ -90,7 +90,7 @@ _shtab_scratch() { if ((${_shtab_scratch_options[(I)${(q)one_or_more}*]} + ${_shtab_scratch_options[(I)${(q)remainder}*]} == 0)); then # noqa: E501 _shtab_scratch_options+=(': :_shtab_scratch_commands' '*::: :->scratch') fi - _arguments -C $_shtab_scratch_options + _arguments -C -s $_shtab_scratch_options case $state in scratch) @@ -98,15 +98,15 @@ _shtab_scratch() { (( CURRENT += 1 )) curcontext="${curcontext%:*:*}:_shtab_scratch-$line[1]:" case $line[1] in - completion) _arguments -C $_shtab_scratch_completion_options ;; - create) _arguments -C $_shtab_scratch_create_options ;; - destroy) _arguments -C $_shtab_scratch_destroy_options ;; - forward) _arguments -C $_shtab_scratch_forward_options ;; - login) _arguments -C $_shtab_scratch_login_options ;; - mine) _arguments -C $_shtab_scratch_mine_options ;; - push) _arguments -C $_shtab_scratch_push_options ;; - sftp) _arguments -C $_shtab_scratch_sftp_options ;; - ssh) _arguments -C $_shtab_scratch_ssh_options ;; + completion) _arguments -C -s $_shtab_scratch_completion_options ;; + create) _arguments -C -s $_shtab_scratch_create_options ;; + destroy) _arguments -C -s $_shtab_scratch_destroy_options ;; + forward) _arguments -C -s $_shtab_scratch_forward_options ;; + login) _arguments -C -s $_shtab_scratch_login_options ;; + mine) _arguments -C -s $_shtab_scratch_mine_options ;; + push) _arguments -C -s $_shtab_scratch_push_options ;; + sftp) _arguments -C -s $_shtab_scratch_sftp_options ;; + ssh) _arguments -C -s $_shtab_scratch_ssh_options ;; esac esac } @@ -114,4 +114,12 @@ _shtab_scratch() { typeset -A opt_args -_shtab_scratch "$@" + +if [[ $zsh_eval_context[-1] == eval ]]; then + # eval/source/. command, register function for later + compdef _shtab_scratch -N scratch +else + # autoload from fpath, call function directly + _shtab_scratch "$@" +fi +