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:
Jan Lindemann 2026-05-31 17:32:59 +02:00
commit 8697695697
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 27 additions and 0 deletions

View 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

View 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)