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:
parent
f4d0828713
commit
cc6febcda3
2 changed files with 12 additions and 2 deletions
|
|
@ -27,7 +27,12 @@ class App: # export
|
|||
def __init__(self, description: str = '', name_filter: str = '^Cmd.*', modules: None=None, eloop: None=None) -> None:
|
||||
|
||||
def add_cmd_to_parser(cmd, parsers):
|
||||
parser = parsers.add_parser(cmd.name, help=cmd.help, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser = parsers.add_parser(
|
||||
cmd.name,
|
||||
help = cmd.help,
|
||||
description = cmd.description,
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.set_defaults(func=cmd.run)
|
||||
cmd.add_arguments(parser)
|
||||
cmd.set_parser(parser)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue