shtab
shtab copied to clipboard
[bug] subparser.help cannot be converted to description
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
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)
any selection -> next TAB only produces -h, --help as a suggestion..
am I doing something wrong ? any help is much appreciated...
Thanks, morphine
Hi, I have the same behaviour. Any fix planned for that? Thanks! Paul