lib.App: Allow _run() without subcommands #20

Merged
Jan Lindemann merged 1 commit from jan/feature/20260617-lib-app-allow-run-without-subcommands into master 2026-06-17 18:49:31 +02:00 AGit

View file

@ -199,10 +199,6 @@ class App: # export
exit_status = 0
if not hasattr(self.__args, 'func'):
self.__parser.print_help()
return None
pr = None if self.__args.write_profile is None else cProfile.Profile()
if pr is not None:
pr.enable()
@ -231,8 +227,14 @@ class App: # export
if exit_status:
sys.exit(exit_status)
# Run sub-command. Overwrite if you want to do anything before or after
# Do the main work. Tries to run sub-commands by default. Overwrite if you
# want to do something else, for instance if you don't have sub-commands,
# or if want to do anything before and / or after the subcommands.
async def _run(self, args: Namespace) -> None | int:
if not hasattr(self.__args, 'func'):
self.__parser.print_help()
return None
# Run sub-command. Overwrite if you want to do anything before or after
return await self.args.func(args)
def call_async(self, awaitable: Awaitable[T], timeout: float | None = None) -> T: