mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 17:45:55 +02:00
lib.Cmd: Add argument "parent" to __init__()
During __init__(), commands have no idea of their parent. This is not a problem as of now, but is easy to fix, and it's architecturally desirable to be prepared just in case, so add the parent argument to the ctor before more commands are added. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
132dce8b3f
commit
f175f9d5c9
32 changed files with 103 additions and 88 deletions
|
|
@ -65,7 +65,6 @@ class App: # export
|
|||
self.__eloop = asyncio.get_event_loop()
|
||||
self.__own_eloop = True
|
||||
|
||||
self.__cmds: list[Cmd] = []
|
||||
self.__parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
description=description, add_help=False)
|
||||
self._add_arguments(self.__parser)
|
||||
|
|
@ -78,7 +77,7 @@ class App: # export
|
|||
|
||||
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_cmds_to_parser(self, self.__parser, [cmd_class() 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
|
||||
self.__parser.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
|
@ -131,7 +130,7 @@ class App: # export
|
|||
|
||||
# Run sub-command. Overwrite if you want to do anything before or after
|
||||
async def _run(self, args: argparse.Namespace) -> None:
|
||||
return await self.__args.func(args)
|
||||
return await self.args.func(args)
|
||||
|
||||
@property
|
||||
def args(self) -> argparse.Namespace:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue