mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
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 <jan@janware.com>
This commit is contained in:
parent
9b208ecc1e
commit
ce1b8b6744
1 changed files with 1 additions and 1 deletions
|
|
@ -87,7 +87,7 @@ class App: # export
|
||||||
log(DEBUG, '-------------- Running: >' + ' '.join(sys.argv) + '<')
|
log(DEBUG, '-------------- Running: >' + ' '.join(sys.argv) + '<')
|
||||||
|
|
||||||
cmd_classes = LoadTypes(modules if modules else ['__main__'], type_name_filter=name_filter, type_filter=[Cmd])
|
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_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
|
# -- Add help only now, wouldn't want to have parse_known_args() exit on --help with subcommands missing
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue