From 047f61f45e0c5947669c5f78d3956f17e5a385d7 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 2 Apr 2024 13:28:36 +0200 Subject: [PATCH] fixed yaml variable in script defaults --- .../ConsolePromptSchema_v1.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Console/ConsolePromptSchema_v1.cs b/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Console/ConsolePromptSchema_v1.cs index bfabfce..cab15dd 100755 --- a/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Console/ConsolePromptSchema_v1.cs +++ b/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Console/ConsolePromptSchema_v1.cs @@ -1,7 +1,6 @@ using Nox.Cli.Abstractions; using Nox.Cli.Abstractions.Exceptions; using Nox.Cli.Abstractions.Extensions; -using Nox.Cli.Helpers; using Nox.Cli.Plugin.Console.JsonSchema; using RestSharp; using Spectre.Console; @@ -550,17 +549,16 @@ private void AppendKey(string yamlSpacing, string key) { if (_defaults?.ContainsKey(key) ?? false) { - var defaultValue = _defaults[key]; - var match = _yamlVariableRegex.Match(defaultValue.ToString()!); - if (match.Success) + var defaultValue = _defaults[key].ToString() ?? ""; + var match = _yamlVariableRegex.Match(defaultValue); + while (match.Success) { var variableValue = _responses[match.Groups["variable"].ToString()].ToString(); - return (T)Convert.ChangeType(defaultValue.ToString()!.Replace(match.Groups[0].ToString(), variableValue), typeof(T)); - } - else - { - return (T)Convert.ChangeType(defaultValue, typeof(T)); + defaultValue = defaultValue.Replace(match.Groups[0].ToString(), variableValue); + match = _yamlVariableRegex.Match(defaultValue); } + return (T)Convert.ChangeType(defaultValue, typeof(T))!; + } return default;