lib.Cmd.print_help(): Add method

Add Cmd.print_help(). By default, it prints a help message. If passed an integer exit_status, it also calls sys.exit(exit_status).

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-05-01 10:17:38 +02:00
commit 30abb227c7
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 6 additions and 3 deletions

View file

@ -13,10 +13,8 @@ class Cmd(Base): # export
super().__init__(parent, name, help) super().__init__(parent, name, help)
async def _run(self, args): async def _run(self, args):
import sys
# Missing subcommand # Missing subcommand
self.parser.print_help() self.print_help(1)
sys.exit(1)
@property @property
def distro(self) -> Distro: def distro(self) -> Distro:

View file

@ -80,6 +80,11 @@ class Cmd(abc.ABC): # export
def child_classes(self) -> list[type[Cmd]]: def child_classes(self) -> list[type[Cmd]]:
return tuple(self.__child_classes) return tuple(self.__child_classes)
def print_help(self, exit_status: int|None=None) -> None:
self.parser.print_help()
if exit_status is not None:
sys.exit(exit_status)
async def run(self, args): async def run(self, args):
return await self._run(args) return await self._run(args)