Skip to content

Commit

Permalink
Add auto-parameter builder to simplify command definition
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Aug 27, 2022
1 parent 26c6590 commit ca33fcd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions schema/v1/ScriptRunnerSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"installCommandWorkingDirectory":{
"type": "string"
},
"autoParameterBuilderPattern":{
"type": "string"
},
"predefinedArgumentSets":{
"type": "array",
"items": {
Expand Down Expand Up @@ -67,6 +70,9 @@
"default": {
"type": "string"
},
"autoParameterBuilderPattern":{
"type": "string"
},
"prompt": {
"type":"string",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class ScriptConfig
public Dictionary<string, string?> EnvironmentVariables { get; set; } = new();
public string? Source { get; set; }
public string? SourceName { get; set; }


public string AutoParameterBuilderPattern { get; set; }
}
public class ArgumentSet
{
Expand All @@ -34,6 +33,7 @@ public class ScriptParam
public PromptType Prompt { get; set; }
public string Default { get; set; }
public Dictionary<string, string> PromptSettings { get; set; } = new();
public string? AutoParameterBuilderPattern { get; set; }

public bool GetPromptSettings(string name, [NotNullWhen(true)] out string? value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,6 +63,22 @@ private static IEnumerable<ScriptConfig> 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);
Expand Down

0 comments on commit ca33fcd

Please sign in to comment.