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] subparser.help cannot be converted to description #105

Open
Freed-Wu opened this issue Sep 7, 2022 · 2 comments
Open

[bug] subparser.help cannot be converted to description #105

Freed-Wu opened this issue Sep 7, 2022 · 2 comments
Labels
enhancement New feature or request external-request You asked, we did p1-important High priority shell-zsh

Comments

@Freed-Wu
Copy link
Contributor

Freed-Wu commented Sep 7, 2022

import argparse
import shtab

parser = argparse.ArgumentParser()
shtab.add_argument_to(parser)
subparsers = parser.add_subparsers(dest="command", help="a")


subparsers.add_parser("test", help="test_help")

parser.parse_args()
❯ python test.py --print-completion zsh|head
#compdef test.py

# AUTOMATCALLY GENERATED by `shtab`


_shtab_test_py_commands() {
  local _commands=(
    "test:"
  )
  _describe 'test.py commands' _commands

test: should be test:test_help

@morphine1
Copy link

Hi,
jap, have the same issue with the following configuration:

def get_arg_parser():
  main_parser = argparse.ArgumentParser(prog=__appname__)

  subparsers = main_parser.add_subparsers(dest="command", title='command')
  parser = subparsers.add_parser("apply", add_help=True, help="apply platform definition to remote cloud provider")

  parser.add_argument("--arg1", type=str, help="Help for argument 1")
  parser.add_argument("arg2", type=str, help="Help for argument 2")

  parser = subparsers.add_parser('destroy', add_help=True, help="destroy resources on cloud provider")
  parser.add_argument("d_arg1", type=str, help="Help for d_argument 1")
  parser.add_argument("d_arg2", type=str, help="Help for d_argument 2")

  return main_parser

command: shtab --verbose --shell=zsh cli.cli.get_arg_parser

verbose output:
DEBUG:shtab.main:Namespace(parser='cli.cli.get_arg_parser', shell='zsh', prefix=None, preamble=None, prog=None, error_unimportable=False, loglevel=10) DEBUG:shtab:choices:_shtab_cli:['apply', 'destroy'] DEBUG:shtab:subcommand:apply DEBUG:shtab:subcommands:apply:{'cmd': 'apply', 'help': '', 'arguments': ['"(- : *)"{-h,--help}"[show this help message and exit]"', '"--arg1[Help for argument 1]:arg1:"', '":Help for argument 2:"'], 'paths': ['apply'], 'commands': {}} DEBUG:shtab:subcommand:destroy DEBUG:shtab:subcommands:destroy:{'cmd': 'destroy', 'help': '', 'arguments': ['"(- : *)"{-h,--help}"[show this help message and exit]"', '":Help for d_argument 1:"', '":Help for d_argument 2:"'], 'paths': ['destroy'], 'commands': {}} DEBUG:shtab:subcommands:_shtab_cli:['_shtab_cli', '_shtab_cli_apply', '_shtab_cli_destroy']

result:

_shtab_cli_commands() { local _commands=( "apply:" "destroy:" ) _describe 'pfm commands' _commands }

additionally, the positional arguments for the sub_parsers are also missing:

_shtab_cli_apply_options=( "(- : *)"{-h,--help}"[show this help message and exit]" "--arg1[Help for argument 1]:arg1:" ":Help for argument 2:" )
_shtab_cli_destroy_options=( "(- : *)"{-h,--help}"[show this help message and exit]" ":Help for d_argument 1:" ":Help for d_argument 2:" )

Resulting in strange behavior on the command line (shell is zsh)

TAB
destroy apply --

any selection -> next TAB only produces -h, --help as a suggestion..

am I doing something wrong ? any help is much appreciated...

Thanks,
morphine

@paulstretenowich
Copy link

Hi,
I have the same behaviour. Any fix planned for that?
Thanks!
Paul

@casperdcl casperdcl added shell-zsh enhancement New feature or request p1-important High priority external-request You asked, we did labels Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request external-request You asked, we did p1-important High priority shell-zsh
Projects
None yet
Development

No branches or pull requests

4 participants