lib.App: Allow _run() without subcommands #20
1 changed files with 7 additions and 5 deletions
|
|
@ -199,10 +199,6 @@ class App: # export
|
||||||
|
|
||||||
exit_status = 0
|
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()
|
pr = None if self.__args.write_profile is None else cProfile.Profile()
|
||||||
if pr is not None:
|
if pr is not None:
|
||||||
pr.enable()
|
pr.enable()
|
||||||
|
|
@ -231,8 +227,14 @@ class App: # export
|
||||||
if exit_status:
|
if exit_status:
|
||||||
sys.exit(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:
|
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)
|
return await self.args.func(args)
|
||||||
|
|
||||||
def call_async(self, awaitable: Awaitable[T], timeout: float | None = None) -> T:
|
def call_async(self, awaitable: Awaitable[T], timeout: float | None = None) -> T:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue