chore(custom-host): Add way to manage PromptForChoice

This commit is contained in:
Scott 2026-08-06 14:43:51 +10:00
commit 6ae34b3c83

View file

@ -121,16 +121,36 @@ public class CustomUiHost : PSHostUserInterface
public string Output => output.ToString(); public string Output => output.ToString();
private int? _nextChoiceOption;
/// <summary>
/// Sets the next choice option to be used on the next call to <see cref="PromptForChoice"/>.
///
/// You'll probably get the
/// </summary>
/// <param name="choiceOption"></param>
public void SetNextPromptChoice(int choiceOption)
{
_nextChoiceOption = choiceOption;
}
public override Dictionary<string, PSObject> Prompt(string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> descriptions) public override Dictionary<string, PSObject> Prompt(string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> 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."); 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.");
} }
public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice) public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
{
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."); 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) public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
{ {
throw new NotImplementedException("PromptForCredential1 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."); throw new NotImplementedException("PromptForCredential1 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.");