From 8697695697f3e73736d704543ee2a3ff8354dd5d Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 31 May 2026 17:32:59 +0200 Subject: [PATCH] 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 --- src/python/jw/pkg/CmdBase.py | 13 +++++++++++++ src/python/jw/pkg/cmds/projects/Cmd.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/python/jw/pkg/CmdBase.py create mode 100644 src/python/jw/pkg/cmds/projects/Cmd.py diff --git a/src/python/jw/pkg/CmdBase.py b/src/python/jw/pkg/CmdBase.py new file mode 100644 index 00000000..65a517b5 --- /dev/null +++ b/src/python/jw/pkg/CmdBase.py @@ -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 diff --git a/src/python/jw/pkg/cmds/projects/Cmd.py b/src/python/jw/pkg/cmds/projects/Cmd.py new file mode 100644 index 00000000..2b3799ba --- /dev/null +++ b/src/python/jw/pkg/cmds/projects/Cmd.py @@ -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)