iterative / shtab

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

bash: Multiple subparser commands don't complete correctly #86

Closed NiklasReisser closed 1 year ago

NiklasReisser commented 2 years ago

Hi,

since #81 , shtab always only completes the first subparser command. The minimal example below immediately completes "bla".

The Reason seems to be that https://github.com/iterative/shtab/blob/60a8525707f10859513c4362ea9c62cd40db93b8/shtab/__init__.py#L357 only expands the first value of the _choices array. Unfortunately, I have not found a solution without breaking #81 again. Happy to try any idea though.


#!/usr/bin/env python3

import argparse
import shtab

parser = argparse.ArgumentParser()
shtab.add_argument_to(parser, ["--print-completion"])

subparsers = parser.add_subparsers()

subparser1 = subparsers.add_parser('bla', help="hi")
subparser2 = subparsers.add_parser('blub', help="hi")

args = parser.parse_args()

Cheers Niklas

pared commented 1 year ago

DVC has issues with that too: https://discord.com/channels/485586884165107732/485596304961962003/1034753563966050395

alkatar21 commented 1 year ago

I have the Issue with DVC tab completion.

Current workaround as suggested in Discord is:

  1. Downgrade shtab (pip install shtab==1.5.4)
  2. dvc completion -s bash | sudo tee /etc/bash_completion.d/dvc
  3. reload terminal/ open a new one, try again
casperdcl commented 1 year ago

Related: #106

shcheklein commented 1 year ago

@casperdcl thanks! :)

shcheklein commented 1 year ago

@alkatar21 could you give the new version a try?

alkatar21 commented 1 year ago

Yes, the subcommands autocomplete correct again, thanks👍