From ca33fcdcabe2fb28065c2a68b4b888b562e1e02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Pi=C4=85tek?= Date: Sat, 27 Aug 2022 10:39:56 +0200 Subject: [PATCH] Add auto-parameter builder to simplify command definition --- schema/v1/ScriptRunnerSchema.json | 6 ++++++ .../ScriptConfigs/ScriptConfig.cs | 4 ++-- .../ScriptReader/ScriptConfigReader.cs | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/schema/v1/ScriptRunnerSchema.json b/schema/v1/ScriptRunnerSchema.json index 14d3196..592b750 100644 --- a/schema/v1/ScriptRunnerSchema.json +++ b/schema/v1/ScriptRunnerSchema.json @@ -31,6 +31,9 @@ "installCommandWorkingDirectory":{ "type": "string" }, + "autoParameterBuilderPattern":{ + "type": "string" + }, "predefinedArgumentSets":{ "type": "array", "items": { @@ -67,6 +70,9 @@ "default": { "type": "string" }, + "autoParameterBuilderPattern":{ + "type": "string" + }, "prompt": { "type":"string", "enum": [ diff --git a/src/ScriptRunner/ScriptRunner.GUI/ScriptConfigs/ScriptConfig.cs b/src/ScriptRunner/ScriptRunner.GUI/ScriptConfigs/ScriptConfig.cs index b1ac495..773de26 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/ScriptConfigs/ScriptConfig.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/ScriptConfigs/ScriptConfig.cs @@ -18,8 +18,7 @@ public class ScriptConfig public Dictionary EnvironmentVariables { get; set; } = new(); public string? Source { get; set; } public string? SourceName { get; set; } - - + public string AutoParameterBuilderPattern { get; set; } } public class ArgumentSet { @@ -34,6 +33,7 @@ public class ScriptParam public PromptType Prompt { get; set; } public string Default { get; set; } public Dictionary PromptSettings { get; set; } = new(); + public string? AutoParameterBuilderPattern { get; set; } public bool GetPromptSettings(string name, [NotNullWhen(true)] out string? value) { diff --git a/src/ScriptRunner/ScriptRunner.GUI/ScriptReader/ScriptConfigReader.cs b/src/ScriptRunner/ScriptRunner.GUI/ScriptReader/ScriptConfigReader.cs index bc924df..e44c443 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/ScriptReader/ScriptConfigReader.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/ScriptReader/ScriptConfigReader.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Text.Json; +using ReactiveUI; using ScriptRunner.GUI.ScriptConfigs; using ScriptRunner.GUI.Settings; @@ -61,6 +63,22 @@ private static IEnumerable LoadFileSource(string fileName) { action.Source = fileName; + var autoParamBuilder = new StringBuilder(); + foreach (var param in action.Params) + { + var actionAutoParameterBuilderPattern = action.AutoParameterBuilderPattern ?? param.AutoParameterBuilderPattern ?? string.Empty; + var paramString = actionAutoParameterBuilderPattern + .Replace("{name}", param.Name) + .Replace("{value}", $"{{{param.Name}}}"); + + if (string.IsNullOrWhiteSpace(paramString) == false) + { + autoParamBuilder.Append($" {paramString}"); + } + } + + action.Command += autoParamBuilder.ToString(); + if (string.IsNullOrWhiteSpace(action.WorkingDirectory)) { action.WorkingDirectory = Path.GetDirectoryName(fileName);