From 6ae34b3c836f6db2de71a650e68564d7a62434cc Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 6 Aug 2026 14:43:51 +1000 Subject: [PATCH] chore(custom-host): Add way to manage PromptForChoice --- src/PowershellHarness/CustomHost.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/PowershellHarness/CustomHost.cs b/src/PowershellHarness/CustomHost.cs index 96ef22b..dcc81ac 100644 --- a/src/PowershellHarness/CustomHost.cs +++ b/src/PowershellHarness/CustomHost.cs @@ -121,6 +121,19 @@ public class CustomUiHost : PSHostUserInterface public string Output => output.ToString(); + private int? _nextChoiceOption; + + /// + /// Sets the next choice option to be used on the next call to . + /// + /// You'll probably get the + /// + /// + public void SetNextPromptChoice(int choiceOption) + { + _nextChoiceOption = choiceOption; + } + public override Dictionary Prompt(string caption, string message, System.Collections.ObjectModel.Collection descriptions) { throw new NotImplementedException("Prompt is not implemented. The script is asking for input, which is a problem since there's no console. Make sure the script can execute without prompting the user for input."); @@ -128,7 +141,14 @@ public class CustomUiHost : PSHostUserInterface public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection choices, int defaultChoice) { - throw new NotImplementedException("PromptForChoice is not implemented. The script is asking for input, which is a problem since there's no console. Make sure the script can execute without prompting the user for input."); + if (_nextChoiceOption is null) + { + throw new NotImplementedException("PromptForChoice is not implemented. The script is asking for input, which is a problem since there's no console. Make sure the script can execute without prompting the user for input."); + } + + var choiceReturn = _nextChoiceOption.Value; + _nextChoiceOption = null; + return choiceReturn; } public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)