Code Monkey home page Code Monkey logo

utility.ps's People

Contributors

jazuntee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

github-coo

utility.ps's Issues

Examples of multiple choice Fields and Choices

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[]]).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.