diff --git a/src/Eryph.ComputeClient.Commands/Catlets/CatletConfigCmdlet.cs b/src/Eryph.ComputeClient.Commands/Catlets/CatletConfigCmdlet.cs
index 7a24357..58c99cd 100644
--- a/src/Eryph.ComputeClient.Commands/Catlets/CatletConfigCmdlet.cs
+++ b/src/Eryph.ComputeClient.Commands/Catlets/CatletConfigCmdlet.cs
@@ -37,16 +37,20 @@ protected static CatletConfig DeserializeConfigString(string configString)
}
- protected void PopulateVariables(CatletConfig catletConfig, Hashtable variables, bool skipVariablesPrompt)
+ ///
+ /// Populates the variables in the given by
+ /// applying the values from the hashtable and
+ /// interactively asking the user for the values. Returns
+ /// when the user aborted the interactive prompt and otherwise.
+ ///
+ protected bool PopulateVariables(CatletConfig catletConfig, Hashtable variables, bool skipVariablesPrompt)
{
if (catletConfig.Variables is not { Length: > 0 })
- return;
+ return true;
ApplyVariablesFromParameter(catletConfig.Variables, variables);
- if (!skipVariablesPrompt)
- {
- ReadVariablesFromInput(catletConfig.Variables);
- }
+
+ return skipVariablesPrompt || ReadVariablesFromInput(catletConfig.Variables);
}
private static void ApplyVariablesFromParameter(VariableConfig[] variableConfigs, Hashtable variables)
@@ -69,7 +73,7 @@ private static void ApplyVariablesFromParameter(VariableConfig[] variableConfigs
}
}
- private void ReadVariablesFromInput(VariableConfig[] variableConfigs)
+ private bool ReadVariablesFromInput(VariableConfig[] variableConfigs)
{
var anyRequired = variableConfigs.Any(vc =>
vc.Required.GetValueOrDefault()
@@ -103,7 +107,7 @@ private void ReadVariablesFromInput(VariableConfig[] variableConfigs)
// The prompt returns -1 when the user cancels the prompt (e.g. Ctrl+C).
if (choice is -1 or 1)
- return;
+ return choice != -1;
var requiredOnly = choice == 2;
@@ -114,17 +118,19 @@ private void ReadVariablesFromInput(VariableConfig[] variableConfigs)
{
var result = ReadVariableFromInput(variableConfig);
if (result is null)
- return;
+ return false;
variableConfig.Value = result;
}
}
- catch (PSInvalidOperationException)
+ catch (Exception ex) when (ex is PSInvalidOperationException or HostException)
{
// The prompt for choice will fail if the Powershell session is not
// interactive. Unfortunately, there is no easy way to reliably detect
// a non-interactive session. Hence, we just catch the exception and continue.
}
+
+ return true;
}
private string ReadVariableFromInput(VariableConfig config)
diff --git a/src/Eryph.ComputeClient.Commands/Catlets/NewCatletCommand.cs b/src/Eryph.ComputeClient.Commands/Catlets/NewCatletCommand.cs
index c2b7e15..c540746 100644
--- a/src/Eryph.ComputeClient.Commands/Catlets/NewCatletCommand.cs
+++ b/src/Eryph.ComputeClient.Commands/Catlets/NewCatletCommand.cs
@@ -102,7 +102,8 @@ protected override void EndProcessing()
if (!string.IsNullOrWhiteSpace(Name))
config.Name = Name;
- PopulateVariables(config, Variables, SkipVariablesPrompt);
+ if (!PopulateVariables(config, Variables, SkipVariablesPrompt))
+ return;
var serializedConfig = JsonSerializer.SerializeToElement(config, ConfigModelJsonSerializer.DefaultOptions);
diff --git a/src/Eryph.ComputeClient.Commands/Catlets/UpdateCatletCommand.cs b/src/Eryph.ComputeClient.Commands/Catlets/UpdateCatletCommand.cs
index c0a726d..6af1ae9 100644
--- a/src/Eryph.ComputeClient.Commands/Catlets/UpdateCatletCommand.cs
+++ b/src/Eryph.ComputeClient.Commands/Catlets/UpdateCatletCommand.cs
@@ -33,20 +33,12 @@ public SwitchParameter NoWait
private bool _nowait;
- [Parameter]
- public Hashtable Variables { get; set; }
-
- [Parameter]
- public SwitchParameter SkipVariablesPrompt { get; set; }
-
protected override void ProcessRecord()
{
foreach (var id in Id)
{
var config = DeserializeConfigString(Config);
- PopulateVariables(config, Variables, SkipVariablesPrompt);
-
WaitForOperation(Factory.CreateCatletsClient().Update(id, new UpdateCatletRequestBody(Guid.NewGuid(),
JsonSerializer.SerializeToElement(config)))
, _nowait, true);
diff --git a/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj b/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj
index ab9deea..e2c573d 100644
--- a/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj
+++ b/src/Eryph.ComputeClient.Commands/Eryph.ComputeClient.Commands.csproj
@@ -9,9 +9,9 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive