lib.Cmd: Add description property

Add keyword-argument description to Cmd.__init__(), and default it to help. Also, add a property .description returning it, and add it to add_parser() so that it shows up in the usage message.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-24 11:53:49 +02:00
commit cc6febcda3
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 12 additions and 2 deletions

View file

@ -12,12 +12,13 @@ from .Types import Types
class Cmd(abc.ABC): # export
def __init__(self, parent: App|Cmd, name: str, help: str) -> None:
def __init__(self, parent: App|Cmd, name: str, help: str, description: str|None=None) -> None:
from . import App
self.__parent: App|Cmd|None = parent
self.__app: App|None = None
self.__name = name
self.__help = help
self.__description = description if description else help
self.__children: list[Cmd] = []
self.__child_classes: list[type[Cmd]] = []
self.__parser: ArgumentParser|None = None
@ -67,6 +68,10 @@ class Cmd(abc.ABC): # export
def help(self) -> str:
return self.__help
@property
def description(self) -> str:
return self.__description
@property
def children(self) -> list[Cmd]:
return tuple(self.__children)