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:
parent
7e2099877c
commit
30abb227c7
2 changed files with 6 additions and 3 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue