Skip to content

Commit

Permalink
do not modify the click command name when it is a MultiCommand #42 (#44)
Browse files Browse the repository at this point in the history
* do not modify the click command name when it is a MultiCommand #42

* add patchable function for register_command
  • Loading branch information
leo-schick authored Feb 14, 2023
1 parent b917eef commit 1d1577e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mara_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def register_commands(self):
if 'callback' in command.__dict__ and command.__dict__['callback']:
package = command.__dict__['callback'].__module__.rpartition('.')[0]
if package != 'flask':
command.name = package + '.' + command.name
self.cli.add_command(command)
register_command(self, command, package)

def register_page_layout(self):
"""Adds a global layout with navigation etc. to pages"""
Expand Down Expand Up @@ -116,6 +115,22 @@ def patch_flask_url_for(self):
flask.url_for = functools.lru_cache(maxsize=None)(original_url_for)


def register_command(app: MaraApp, command: click.Command, package: str):
"""
Register a new command to a mara flask app.
Args
app: the mara flask app
command: the command to be added
package: the python package name the command comes from
"""
if isinstance(command, click.MultiCommand):
app.cli.add_command(command)
else:
command.name = package + '.' + command.name
app.cli.add_command(command)


@functools.lru_cache(maxsize=None)
def combine_navigation_entries() -> navigation.NavigationEntry:
"""Collects and merges all instances of NavigationEntry"""
Expand Down

0 comments on commit 1d1577e

Please sign in to comment.