Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] REMAINDER miss a : #125

Open
Freed-Wu opened this issue Dec 12, 2022 · 0 comments
Open

[bug] REMAINDER miss a : #125

Freed-Wu opened this issue Dec 12, 2022 · 0 comments
Labels
good-first-issue Good for newcomers (good-first-issue) help-wanted We need help p1-important High priority

Comments

@Freed-Wu
Copy link
Contributor

Freed-Wu commented Dec 12, 2022

The following example comes from /usr/share/zsh/functions/Completion/Unix/_sudo

file a:

#!/usr/bin/env python
from argparse import ArgumentParser
import shtab

parser = ArgumentParser()
shtab.add_argument_to(parser)
parser.add_argument("command", nargs=1).complete = {"zsh": "{_command_names -e}"}
parser.add_argument("args", nargs="...").complete = {"zsh": "_normal"}
parser.parse_args()
$ ./a --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_a
#compdef a

# AUTOMATICALLY GENERATED by `shtab`


_shtab_a_commands() {
  local _commands=(

  )
  _describe 'a commands' _commands
}

_shtab_a_options=(
  "(- : *)"{-h,--help}"[show this help message and exit]"
  "(- : *)--print-completion[print shell completion script]:print_completion:(bash zsh tcsh)"
  ":command:{_command_names -e}"
  "(-)*:args:_normal"
)


_shtab_a() {
  local context state line curcontext="$curcontext" one_or_more='(-)*' remainder='(*)'

  if ((${_shtab_a_options[(I)${(q)one_or_more}*]} + ${_shtab_a_options[(I)${(q)remainder}*]} == 0)); then  # noqa: E501
    _shtab_a_options+=(': :_shtab_a_commands' '*::: :->a')
  fi
  _arguments -C $_shtab_a_options

  case $state in
    a)
      words=($line[1] "${words[@]}")
      (( CURRENT += 1 ))
      curcontext="${curcontext%:*:*}:_shtab_a-$line[1]:"
      case $line[1] in

      esac
  esac
}



typeset -A opt_args
_shtab_a "$@"

command will complete all executable command, and normal will complete its arguments

We got error:

$ a ls <TAB>
_tags:comptags:60: nesting level too deep

If we change

  "(-)*:args:_normal"

to

  "(-)*::args:_normal"

The nested bug can disappear. Refer https://github.com/zsh-users/zsh/blob/a9386df5581487e5e34ecb3ce422bacf62d10c3d/Completion/Unix/Command/_sudo#L61-L62:

    "(-)1: :{ $cpp; _command_names -e }"
    "*:: :{ $cpp; _normal }"

It is https://github.com/iterative/shtab/blob/main/shtab/__init__.py#L497 REAMINDER can be *: or (-)*:.

@omesser omesser added help-wanted We need help p1-important High priority good-first-issue Good for newcomers (good-first-issue) labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Good for newcomers (good-first-issue) help-wanted We need help p1-important High priority
Projects
None yet
Development

No branches or pull requests

2 participants