subcommands don't get description but get help anyway
Thank you for the project, I like the idea to stick to a small Python app for it and re-use some well known APIs...
... but struggle generating some completion file. I think there are some issues in shtab but it could also be a mis-usage.
- Using https://github.com/hyprland-community/pyprland/blob/main/scripts/pypr.py
- Running
shtab -u --prog pypr --shell=zsh pypr.get_parser
- it looks like
add_helpoption to ArgumentParser only applies to the "root", I couldn't find a way to also avoid it in subparsers - the generated completion looks fine but misses the description for every subcommand
I believe you have to set the description= on .add_parser to get the description to show up in the autocomplete layer.
Also, you'll need keep help= to avoid the subparser getting skipped/hidden. I believe the specific value of "help=" is never used within shtab.
Here's an example to experiment with:
https://gist.github.com/mpkocher/e20563d11a978692a647d20850545445
Shtab does a good job of logging to help debugging. Adding logging.basicConfig(level=logging.DEBUG, stream=sys.stderr) or similar can be helpful to see what if a subparser skipped or "hidden".
For example, with no help= defined on the subparser, you'll see this:
DEBUG:shtab:choices:_shtab_shtab_test_py:['alpha', 'beta']
DEBUG:shtab:skip:subcommand:alpha
DEBUG:shtab:skip:subcommand:beta
DEBUG:shtab:subcommands:_shtab_shtab_test_py:['_shtab_shtab_test_py']
#compdef shtab_test.py
# AUTOMATICALLY GENERATED by `shtab`
_shtab_shtab_test_py_commands() {
local _commands=(
)
_describe 'shtab_test.py commands' _commands
}
Setting help= will yield:
DEBUG:shtab:choices:_shtab_shtab_test_py:['alpha', 'beta']
DEBUG:shtab:subcommand:alpha
DEBUG:shtab:subcommands:alpha:{'cmd': 'alpha', 'help': '*DESC Run alpha', 'arguments': ['"(- : *)"{-h,--help}"[show this help message and exit]"', '{-i,--input}"[Path to input file]:input:_files"'], 'paths': ['alpha'], 'commands': {}}
DEBUG:shtab:subcommand:beta
DEBUG:shtab:subcommands:beta:{'cmd': 'beta', 'help': '*DESC Run beta', 'arguments': ['"(- : *)"{-h,--help}"[show this help message and exit]"', '{-s,--src}"[]:src:_files -/"', '{-d,--dest}"[]:dest:_files"'], 'paths': ['beta'], 'commands': {}}
DEBUG:shtab:subcommands:_shtab_shtab_test_py:['_shtab_shtab_test_py', '_shtab_shtab_test_py_alpha', '_shtab_shtab_test_py_beta']
#compdef shtab_test.py
# AUTOMATICALLY GENERATED by `shtab`
_shtab_shtab_test_py_commands() {
local _commands=(
"alpha:\*DESC Run alpha"
"beta:\*DESC Run beta"
)
_describe 'shtab_test.py commands' _commands