From dee8156a0c2263ac4d75fba9a957ebfd582dff14 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 9 Nov 2021 16:56:17 +0100 Subject: [PATCH] implemented 'add_modules' which will call cli method on module to give ability to register custom cli commands --- openpype/cli.py | 1 + openpype/pype_commands.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/openpype/cli.py b/openpype/cli.py index e1f9265c1f..d68cba45c6 100644 --- a/openpype/cli.py +++ b/openpype/cli.py @@ -57,6 +57,7 @@ def tray(debug=False): PypeCommands().launch_tray(debug) +@PypeCommands.add_modules @main.group(help="Run command line arguments of OpenPype modules") @click.pass_context def module(ctx): diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index 5fac5cacc7..f4a29091d0 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -41,6 +41,17 @@ class PypeCommands: user_role = "manager" settings.main(user_role) + @staticmethod + def add_modules(click_func): + """Modules/Addons can add their cli commands dynamically.""" + from openpype.modules import ModulesManager + + manager = ModulesManager() + for module in manager.modules: + if hasattr(module, "cli"): + module.cli(click_func) + return click_func + @staticmethod def launch_eventservercli(*args): from openpype_modules.ftrack.ftrack_server.event_server_cli import (