completion: use new get_completion_script method

This commit is contained in:
Thomas Waldmann 2026-03-02 16:13:15 +01:00
parent f2bdb689c5
commit 4a6b4130ef
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
2 changed files with 5 additions and 14 deletions

View file

@ -67,7 +67,6 @@ from ..helpers import (
)
from ..helpers.argparsing import ArgumentParser
from ..helpers.argparsing import _ActionSubCommands
from ..helpers.argparsing import prepare_actions_context, shtab_prepare_actions, bash_compgen_typehint
from ..helpers.time import timestamp
from ..helpers.parseformat import partial_format
from ..manifest import AI_HUMAN_SORT_KEYS
@ -732,19 +731,13 @@ class CompletionMixIn:
bash_preamble = partial_format(BASH_PREAMBLE_TMPL, mapping)
zsh_preamble = partial_format(ZSH_PREAMBLE_TMPL, mapping)
parser.prog = "borg"
prog = "borg"
preambles = []
if args.shell == "bash":
preambles.append(bash_compgen_typehint.strip().replace("%s", prog))
preambles.append(bash_preamble)
preambles = [bash_preamble]
elif args.shell == "zsh":
preambles.append(zsh_preamble)
with prepare_actions_context(args.shell, prog, preambles):
shtab_prepare_actions(parser)
script = shtab.complete(parser, shell=args.shell, preamble="\n".join(preambles)) # nosec B604
preambles = [zsh_preamble]
else:
preambles = []
script = parser.get_completion_script(f"shtab-{args.shell}", preambles=preambles)
print(script)
def build_parser_completion(self, subparsers, common_parser, mid_common_parser):

View file

@ -106,8 +106,6 @@ from jsonargparse.typing import PositiveInt # noqa: F401
# borg completion uses these private symbols, so we need to import them:
from jsonargparse._actions import _ActionSubCommands # noqa: F401
from jsonargparse._completions import prepare_actions_context, shtab_prepare_actions # noqa: F401
from jsonargparse._completions import bash_compgen_typehint # noqa: F401
class ArgumentParser(_ArgumentParser):