mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-28 21:54:34 +02:00
DistroBase's option --id is now redundant to the new global option --distro-id in the App class, so remove --id. The only added value DistroBase then brings to the table is its .distro property, which can be provided by App just fine at this point, given that App has all it needs to construct a Distro object, so add .distro to App and remove the entire DistroBase class. For convenience, also make App.distro available as a newly added cmds.Cmd.distro property. This also obviates the need for the distro-related properties in the .distro.Cmd class, remove all that. Signed-off-by: Jan Lindemann <jan@janware.com>
30 lines
874 B
Python
30 lines
874 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import annotations
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from ..App import App
|
|
from ..lib.Cmd import Cmd as Base
|
|
from ..lib.Types import LoadTypes
|
|
|
|
class Cmd(Base): # export
|
|
|
|
def __init__(self, parent: App|Base, name: str, help: str) -> None:
|
|
super().__init__(parent, name, help)
|
|
|
|
def _add_subcommands(self) -> None:
|
|
# Derive module search path for the calling module's subcommands from
|
|
# the module path of the calling module itself
|
|
cmds_module = type(self).__module__.replace('Cmd', '').lower()
|
|
self.add_subcommands(LoadTypes([cmds_module], type_name_filter=r'Cmd[^.]'))
|
|
|
|
async def _run(self, args):
|
|
import sys
|
|
# Missing subcommand
|
|
self.parser.print_help()
|
|
sys.exit(1)
|
|
|
|
@property
|
|
def distro(self) -> Distro:
|
|
return self.app.distro
|