CmdBase / cmds.projects.Cmd: Add modules
Lots of sub- and sub-subcommands are derived from the base class of the invoking command, notably below cmds.projects. That provides some properties shared across the ancestor hierarchy of a command, but is semantically unsound. Introduce jw.pkg.BaseCmd class as a place to provide basic helpers shared across all commands used in a jw.pkg.App's context. Also add cmds.projects.Cmd to be used by other commands in cmds.projects in later commits.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
13ec34cc57
commit
8697695697
2 changed files with 27 additions and 0 deletions
13
src/python/jw/pkg/CmdBase.py
Normal file
13
src/python/jw/pkg/CmdBase.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
from .App import App
|
||||||
|
from .lib.Cmd import Cmd as Base
|
||||||
|
|
||||||
|
class CmdBase(Base):
|
||||||
|
|
||||||
|
@property
|
||||||
|
def app(self) -> App:
|
||||||
|
ret = super().app
|
||||||
|
if not isinstance(ret, App):
|
||||||
|
raise TypeError(
|
||||||
|
f'Expected {self.__class__.__name__}, got {type(ret).__name__}'
|
||||||
|
)
|
||||||
|
return ret
|
||||||
14
src/python/jw/pkg/cmds/projects/Cmd.py
Normal file
14
src/python/jw/pkg/cmds/projects/Cmd.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
from ...CmdBase import CmdBase
|
||||||
|
from ..CmdProjects import CmdProjects as Parent
|
||||||
|
|
||||||
|
class Cmd(CmdBase): # export
|
||||||
|
|
||||||
|
def __init__(self, parent: Parent, name: str, help: str) -> None:
|
||||||
|
super().__init__(parent, name, help)
|
||||||
|
|
||||||
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
super().add_arguments(parser)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue