Skip to content

Commit

Permalink
(#208) Improve UX of Crescendo cmdlets
Browse files Browse the repository at this point in the history
This commit begins the work of improving the author experience when
accelerating a native command.

This commit exposes all properties off the Command class to the user
via the New-CrescendoCommand cmdlet. Further to exposing all available
properties, an ArgumentCompleter attribute has been introduced to the
Verb parameter to allow for tab completion of PowerShell built-in
approved verbs.
  • Loading branch information
steviecoaster committed Apr 11, 2024
1 parent 08a8ac3 commit 1fa447b
Showing 1 changed file with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Command {
Command() {
$this.Platform = "Windows","Linux","MacOS"
}
Command([string]$Verb, [string]$Noun)
Command([string]$Verb, [string]$Noun,[string]$OriginalName,$Description)
{
$this.Verb = $Verb
$this.Noun = $Noun
Expand Down Expand Up @@ -681,13 +681,95 @@ function New-OutputHandler {
function New-CrescendoCommand {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions","")]
param (
[Parameter(Position=0,Mandatory=$true)][string]$Verb,
[Parameter(Position=1,Mandatory=$true)][string]$Noun,
[Parameter(Position=2)][string]$OriginalName
[Parameter(Position=0,Mandatory=$true)]
[ArgumentCompleter( {
param ( $commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters )
if ($WordToComplete) {
(Get-Verb).Verb | Where-Object { $_ -match "^$WordToComplete"}
}

else {
(Get-Verb).Verb
}
} )]
[string]
$Verb,

[Parameter(Position=1,Mandatory=$true)]
[string]
$Noun,

[Parameter(Position=2)]
[string]
$OriginalName,

[Parameter(Position=3)]
[string]
$Description,

[Parameter()]
[string[]]
$Aliases,

[Parameter()]
[string] $DefaultParameterSetName,

[Parameter()]
[bool]
$SupportsShouldProcess,

[Parameter()]
[string]
$ConfirmImpact,

[Parameter()]
[bool]
$SupportsTransactions,

[Parameter()]
[bool]
$NoInvocation,
# certain scenarios want to use the generated code as a front end. When true, the generated code will return the arguments only.
[Parameter()]
[UsageInfo]
$Usage,

[Parameter()]
[List[ParameterInfo]]
$Parameters,

[Parameter()]
[List[ExampleInfo]]
$Examples,

[Parameter()]
[string]
$OriginalText,

[Parameter()]
[string[]]
$HelpLinks,

[Parameter()]
[OutputHandler[]]
$OutputHandlers



)
$cmd = [Command]::new($Verb, $Noun)
$cmd.OriginalName = $OriginalName

$cmd = [Command]::new($Verb, $Noun,$OriginalName,$Description)

$PSBoundParameters.GetEnumerator() |
ForEach-Object {
$cmd.$($psitem.Key) = $PSItem.Value
}
$cmd

}

function Export-CrescendoCommand {
Expand Down

0 comments on commit 1fa447b

Please sign in to comment.