jazuntee / utility.ps Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Alright - so this definitely isn't an issue, but since you have so many great examples, I figured I'd let you know another example that might be helpful to truly make your Write-HostPrompt
the full deal if anyone else comes across it and decides to use it.
Some examples are here: https://github.com/PowerShell/vscode-powershell/blob/master/examples/PromptExamples.ps1
What I think is most helpful, and notably missing from your current examples, are using arrays to allow multiple fields. The example in the link above is basically multiple choice and seems like an overload, but isn't truly. Below is also an overengineered example that makes creating a ChoicePrompt
somewhat easier - although applications would certainly be limited.
function Create-ChoicePrompt{
[System.Management.Automation.Host.FieldDescription]$Title = "Title"
[System.Management.Automation.Host.FieldDescription]$Message = "Message"
[System.Management.Automation.Host.FieldDescription]$Choices = "Choices"
[System.Management.Automation.Host.FieldDescription]$DefaultChoice = "DefaultChoice"
$Choices.SetParameterType([string[]])
$DefaultChoice.SetParameterType([int])
$DefaultChoice.DefaultValue = 0
[System.Management.Automation.Host.FieldDescription[]]$Fields = $Title, $Message, $Choices, $DefaultChoice
$Host.UI.Prompt("Choice Prompt Helper", "Enter the items below to generate arguments for a user choice",$Fields)
}
$HostPromptArguments = Create-ChoicePrompt
Write-HostPrompt @HostPromptArguments
The most salient detail that might be worth adding an example is that you can use .SetParameterType()
to use arrays as well as single data types. So in your [datetime]
example, if you wanted to get multiple dates/times, you could use $DateTimeField.SetParameterType([datetime[]])
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.