iterative / shtab

↔️ Automagic shell tab completion for Python CLI applications
https://docs.iterative.ai/shtab
Other
362 stars 35 forks source link

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

Open Freed-Wu opened 1 year ago

Freed-Wu commented 1 year ago

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:"
)