jw-pkg/src/python/jw/pkg/cmds/Cmd.py

30 lines
874 B
Python
Raw Normal View History

# -*- 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