From ce1b8b674494f6f47ec9f5828ad5912386fcea52 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 25 Mar 2026 20:26:21 +0100 Subject: [PATCH] lib.App: Fully parse argparse tree if _ARGCOMPLETE Every module derived from lib.Cmd implements its own parser.add_argument() logic. As a consequence, all Cmd derived modules need to be loaded to have the full argument tree available. This is avoided during normal program startup because it takes some time. It's not necessary during normal program execution, nor for showing help messages. It is, however, needed for argcomplete to do its thing, so fully parse the command line if the program runs in argcomplete mode, as determined by checking if _ARGCOMPLETE is present in the environment. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/App.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/jw/pkg/lib/App.py b/src/python/jw/pkg/lib/App.py index 566c3691..98432d01 100644 --- a/src/python/jw/pkg/lib/App.py +++ b/src/python/jw/pkg/lib/App.py @@ -87,7 +87,7 @@ class App: # export log(DEBUG, '-------------- Running: >' + ' '.join(sys.argv) + '<') cmd_classes = LoadTypes(modules if modules else ['__main__'], type_name_filter=name_filter, type_filter=[Cmd]) - add_all_parsers = '-h' in sys.argv or '--help' in sys.argv + add_all_parsers = '-h' in sys.argv or '--help' in sys.argv or '_ARGCOMPLETE' in os.environ add_cmds_to_parser(self, self.__parser, [cmd_class(self) for cmd_class in cmd_classes], all=add_all_parsers) # -- Add help only now, wouldn't want to have parse_known_args() exit on --help with subcommands missing