From 21663c109285ef15bfe30524aee1073a69a65756 Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Tue, 21 Nov 2023 10:31:24 +0100 Subject: [PATCH] add option to shorten cli commands by removing prefix 'mara-' and 'mara_' --- mara_app/app.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mara_app/app.py b/mara_app/app.py index 28e3b06..c04239e 100644 --- a/mara_app/app.py +++ b/mara_app/app.py @@ -43,7 +43,11 @@ def module_functionalities(module: types.ModuleType, MARA_XXX: str, type) -> []: class MaraApp(flask.Flask): - def __init__(self): + def __init__(self, shorten_cli_commands: bool = False): + """ + Args: + shorten_cli_commands: (Optional) if set, the cli command prefix 'mara-' and 'mara_' will be removed + """ super().__init__('mara') self.register_blueprints() self.register_commands() @@ -52,6 +56,7 @@ def __init__(self): self.disable_caching() self.patch_flask_url_for() self.config.update(config.flask_config()) + self.shorten_cli_commands = shorten_cli_commands def register_blueprints(self): """Searches for all declared blueprints and adds them to the app""" @@ -66,6 +71,10 @@ def register_commands(self): if 'callback' in command.__dict__ and command.__dict__['callback']: package = command.__dict__['callback'].__module__.rpartition('.')[0] if package != 'flask': + # remove prefix 'mara_' and 'mara-' from the command name + if self.shorten_cli_commands and (command.name.startswith('mara-') or \ + command.name.startswith('mara_')): + command.name = command.name[5:] register_command(self, command, package) def register_page_layout(self):