shtab tripped up by Waydroid argparse parser with subcommands.
I'm using shtab 1.7.2.dev0+g61ec99d.d20241116 on Arch Linux, trying to generate tab completion for Waydroid. Waydroid installs to /usr/lib/waydroid without installing itself as a python module, so I first cd /usr/lib/waydroid. Then, running shtab tools.helpers.arguments generates a usage error from the Waydroid parser:
$ shtab tools.helpers.arguments
usage: waydroid [-h] [-V] [-l LOG] [--details-to-stdout] [-v] [-q] [-w] {status,log,init,upgrade,session,container,app,prop,show-full-ui,first-launch,shell,logcat} ...
waydroid: error: argument action: invalid choice: 'tools.helpers.arguments' (choose from status, log, init, upgrade, session, container, app, prop, show-full-ui, first-launch, shell, logcat)
The "invalid choice" indicates that the module path is getting interpreted as a subcommand, so I figured this is what the --prog shtab option is for.
Trying shtab --prog=status tools.helpers.arguments produces the exact same output as before.
Trying shtab --prog status tools.helpers.arguments (space instead of equals) results in Waydroid's parser complaining:
waydroid: error: unrecognized arguments: --prog tools.helpers.arguments
At this point I gave up. I'm not sure what's going wrong here, but I figured it's worth reporting. For others trying to autocomplete Waydroid, it turns out that it does have argcomplete support, and that works.
It's because the function is returning args instead of parser, vis. waydroid@45ded8c:/tools/helpers/arguments.py:168.
This is probably bad practice, and worth opening an issue on Waydroid. Usually only __name__ == "__main__" guarded code should run parse_args(). Right now you can't even python -c "import tools"