lib.App: Allow _run() without subcommands
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m5s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m11s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m8s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m17s
CI / Packaging test (push) Successful in 0s

Overriding the _run() method entirely in App subclasses is currently only possible if the application supports a subcommand structure. Make it possible to use it as an abstraction for a single-command application.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-13 18:27:59 +02:00
commit ffe0cfd41d
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

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: