build.cmds: Move build.App.cmd_xxx() here

For every cmd_xxx() method in build.App, create a class that's
instatiated for running the respective command. This has the
advantage of making App.py smaller (and faster), and having smaller,
more maintainable command modules adhering to a common interface.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-11-16 11:39:27 +01:00
commit ac583f76e1
24 changed files with 715 additions and 439 deletions

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from ..Cmd import Cmd
class CmdCommands(Cmd): # export
def __init__(self) -> None:
super().__init__('commands', help='List available commands')
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
def _run(self, args: Namespace) -> None:
import sys, re, os, glob
this_dir = os.path.dirname(sys.modules[__name__].__file__)
ret = []
for file_name in glob.glob('Cmd*.py', root_dir=this_dir):
cc_name = re.sub(r'^Cmd|\.py', '', file_name)
name = re.sub(r'(?<!^)(?=[A-Z])', '-', cc_name).lower()
ret.append(name)
print(' '.join(ret))