From 58e41e1426e3d8c3c058ebb1c94604c2ddec72c5 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Fri, 20 Dec 2024 17:03:08 +0100 Subject: [PATCH] [app] Add `--env-help` command line option Add a new CLI option to print the available Meshroom environment variables and their descriptions. --- meshroom/env.py | 17 +++++++++++++++++ meshroom/ui/app.py | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/meshroom/env.py b/meshroom/env.py index d3b6da3057..3036db206f 100644 --- a/meshroom/env.py +++ b/meshroom/env.py @@ -4,8 +4,10 @@ __all__ = [ "EnvVar", + "EnvVarHelpAction", ] +import argparse import os from dataclasses import dataclass from enum import Enum @@ -51,3 +53,18 @@ def _cast(value: str, valueType: Type) -> Any: return value.lower() in {"true", "1", "on"} return valueType(value) + @classmethod + def help(cls) -> str: + """Return a formatted string with the details of each environment variables.""" + return "\n".join([f"{var.name}: {var.value}" for var in cls]) + + +class EnvVarHelpAction(argparse.Action): + """Argparse action for printing Meshroom environment variables help and exit.""" + + DEFAULT_HELP = "Print Meshroom environment variables help and exit." + + def __call__(self, parser, namespace, value, option_string=None): + print("Meshroom environment variables:") + print(EnvVar.help()) + sys.exit(0) diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index d19f7652e8..888d2f7c36 100644 --- a/meshroom/ui/app.py +++ b/meshroom/ui/app.py @@ -17,7 +17,7 @@ from meshroom.core.taskManager import TaskManager from meshroom.common import Property, Variant, Signal, Slot -from meshroom.env import EnvVar +from meshroom.env import EnvVar, EnvVarHelpAction from meshroom.ui import components from meshroom.ui.components.clipboard import ClipboardHelper @@ -185,6 +185,14 @@ def createMeshroomParser(args): + '\n'.join([' - ' + p for p in meshroom.core.pipelineTemplates]), ) + advanced_group = parser.add_argument_group("Advanced Options") + advanced_group.add_argument( + "--env-help", + action=EnvVarHelpAction, + nargs=0, + help=EnvVarHelpAction.DEFAULT_HELP, + ) + return parser.parse_args(args[1:])