mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
jw-pkg.sh: Print help for missing subcommands
Print a help message if no subcommand is specified for one of the comamnds "distro" and "projects". Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
32b28b5958
commit
c8036ad216
4 changed files with 16 additions and 2 deletions
|
|
@ -43,4 +43,6 @@ class CmdDistro(CmdBase): # export
|
|||
return self.__interactive
|
||||
|
||||
async def _run(self, args):
|
||||
raise Exception("Running with args", args)
|
||||
# Missing subcommand
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
|
|
|
|||
|
|
@ -16,4 +16,6 @@ class CmdProjects(CmdBase): # export
|
|||
super().add_arguments(p)
|
||||
|
||||
async def _run(self, args):
|
||||
raise Exception("Running with args", args)
|
||||
# Missing subcommand
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class App: # export
|
|||
parser = parsers.add_parser(cmd.name, help=cmd.help, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.set_defaults(func=cmd.run)
|
||||
cmd.add_arguments(parser)
|
||||
cmd.set_parser(parser)
|
||||
return parser
|
||||
|
||||
def add_cmds_to_parser(parent, parser, cmds, all=False):
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class Cmd(abc.ABC): # export
|
|||
self.__help = help
|
||||
self.__children: list[Cmd] = []
|
||||
self.__child_classes: list[type[Cmd]] = []
|
||||
self.__parser: ArgumentParser|None = None
|
||||
|
||||
@abc.abstractmethod
|
||||
async def _run(self, args) -> None:
|
||||
|
|
@ -50,6 +51,14 @@ class Cmd(abc.ABC): # export
|
|||
parent = parent.__parent
|
||||
return self.__app
|
||||
|
||||
# Don't use a setter decorator to force using a grepable method
|
||||
def set_parser(self, parser: ArgumentParser):
|
||||
self.__parser = parser
|
||||
|
||||
@property
|
||||
def parser(self) -> str:
|
||||
return self.__parser
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self.__name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue