Skip to content

Commit

Permalink
add option to shorten cli commands by removing prefix 'mara-' and 'ma…
Browse files Browse the repository at this point in the history
…ra_'
  • Loading branch information
leo-schick committed Nov 21, 2023
1 parent f127ea1 commit 21663c1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mara_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"""
Expand All @@ -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):
Expand Down

0 comments on commit 21663c1

Please sign in to comment.