shtab icon indicating copy to clipboard operation
shtab copied to clipboard

bash: Multiple subparser commands don't complete correctly

Open NiklasReisser opened this issue 3 years ago • 0 comments

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

NiklasReisser avatar Aug 05 '22 17:08 NiklasReisser