shtab icon indicating copy to clipboard operation
shtab copied to clipboard

[bug] zsh completion has wrong order for many `nargs=?`s

Open Freed-Wu opened this issue 2 years ago • 0 comments

Such as https://github.com/jaraco/keyring/pull/611

        self.parser.add_argument(
            'operation',
            choices=["get", "set", "del"],
            nargs="?",
        )
        self.parser.add_argument(
            'service',
            nargs="?",
        )
        self.parser.add_argument(
            'username',
            nargs="?",
        )

will generate

_shtab_keyring_options=(
  "(- : *)"{-h,--help}"[show this help message and exit]"
  "(- : *)--print-completion[print shell completion script]:print_completion:(bash zsh tcsh)"
  {-p,--keyring-path}"[Path to the keyring backend]:keyring_path:_files -/"
  {-b,--keyring-backend}"[Name of the keyring backend]:keyring_backend:keyring_complete"
  "--list-backends[List keyring backends and exit]"
  "--disable[Disable keyring and exit]"
  ":service:"
  ":username:"
  ":operation:(get set del)"
)

Expected:

_shtab_keyring_options=(
  "(- : *)"{-h,--help}"[show this help message and exit]"
  "(- : *)--print-completion[print shell completion script]:print_completion:(bash zsh tcsh)"
  {-p,--keyring-path}"[Path to the keyring backend]:keyring_path:_files -/"
  {-b,--keyring-backend}"[Name of the keyring backend]:keyring_backend:keyring_complete"
  "--list-backends[List keyring backends and exit]"
  "--disable[Disable keyring and exit]"
  ":operation:(get set del)"
  ":service:"
  ":username:"
)

Freed-Wu avatar Dec 08 '22 03:12 Freed-Wu