From d4b131700a54df516e18abbb8a0a31d828fca990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 10 Aug 2023 12:45:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20config=20cli:=20Init=20plugin=20?= =?UTF-8?q?settings=20if=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we won't be able to access the plugin default values and that leads to issues on querying full plugin setting trees. Fixes #4835 --- src/octoprint/cli/config.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/octoprint/cli/config.py b/src/octoprint/cli/config.py index 7ace969c5..debfc78a8 100644 --- a/src/octoprint/cli/config.py +++ b/src/octoprint/cli/config.py @@ -8,7 +8,7 @@ import pprint import click -from octoprint import FatalStartupError, init_settings +from octoprint import FatalStartupError, init_pluginsystem, init_settings from octoprint.cli import get_ctx_obj_option, standard_options from octoprint.util import yaml @@ -41,6 +41,17 @@ def _set_helper(settings, path, value, data_type=None): settings.save() +def _init_pluginsettings(ctx): + try: + ctx.obj.plugin_manager = init_pluginsystem( + ctx.obj.settings, safe_mode=get_ctx_obj_option(ctx, "safe_mode", False) + ) + except FatalStartupError as e: + click.echo(str(e), err=True) + click.echo("There was a fatal error initializing the plugin manager.", err=True) + ctx.exit(-1) + + # ~~ "octoprint config" commands @@ -112,6 +123,8 @@ def remove_command(ctx, path): def append_value_command(ctx, path, value, as_json=False): """Appends value to list behind config path.""" path = _to_settings_path(path) + if len(path) == 0 or path[0] == "plugins": + _init_pluginsettings(ctx) if as_json: try: @@ -141,6 +154,8 @@ def append_value_command(ctx, path, value, as_json=False): def insert_value_command(ctx, path, index, value, as_json=False): """Inserts value at index of list behind config key.""" path = _to_settings_path(path) + if len(path) == 0 or path[0] == "plugins": + _init_pluginsettings(ctx) if as_json: try: @@ -169,6 +184,8 @@ def insert_value_command(ctx, path, index, value, as_json=False): def remove_value_command(ctx, path, value, as_json=False): """Removes value from list at config path.""" path = _to_settings_path(path) + if len(path) == 0 or path[0] == "plugins": + _init_pluginsettings(ctx) if as_json: try: @@ -204,6 +221,8 @@ def remove_value_command(ctx, path, value, as_json=False): def get_command(ctx, path, as_json=False, as_yaml=False, as_raw=False): """Retrieves value from config path.""" path = _to_settings_path(path) + if len(path) == 0 or path[0] == "plugins": + _init_pluginsettings(ctx) value = ctx.obj.settings.get(path, merged=True) if as_json: @@ -228,6 +247,7 @@ def get_command(ctx, path, as_json=False, as_yaml=False, as_raw=False): @click.pass_context def effective_command(ctx, as_json=False, as_yaml=False, as_raw=False): """Retrieves the full effective config.""" + _init_pluginsettings(ctx) value = ctx.obj.settings.effective if as_json: