2025-11-15 14:41:07 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
2026-01-20 15:49:53 +01:00
|
|
|
|
2025-11-15 14:41:07 +01:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
2026-01-27 10:22:16 +01:00
|
|
|
from ..App import App
|
2026-01-21 14:29:10 +01:00
|
|
|
from ..lib.Cmd import Cmd as Base
|
2026-01-20 15:49:53 +01:00
|
|
|
from ..lib.Types import LoadTypes
|
2026-01-21 14:29:10 +01:00
|
|
|
|
|
|
|
|
class Cmd(Base): # export
|
2025-11-15 14:41:07 +01:00
|
|
|
|
2026-01-27 10:22:16 +01:00
|
|
|
def __init__(self, parent: App|Base, name: str, help: str) -> None:
|
|
|
|
|
super().__init__(parent, name, help)
|
2026-01-20 15:49:53 +01:00
|
|
|
|
|
|
|
|
def _add_subcommands(self) -> None:
|
2026-02-23 09:21:34 +01:00
|
|
|
# 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[^.]'))
|
2026-03-07 11:08:14 +01:00
|
|
|
|
|
|
|
|
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
|