Skip to content

Commit 1fa447b

Browse files
committed
(#208) Improve UX of Crescendo cmdlets
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.
1 parent 08a8ac3 commit 1fa447b

File tree

1 file changed

+88
-6
lines changed

1 file changed

+88
-6
lines changed

Microsoft.PowerShell.Crescendo/src/Microsoft.PowerShell.Crescendo.psm1

+88-6
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class Command {
233233
Command() {
234234
$this.Platform = "Windows","Linux","MacOS"
235235
}
236-
Command([string]$Verb, [string]$Noun)
236+
Command([string]$Verb, [string]$Noun,[string]$OriginalName,$Description)
237237
{
238238
$this.Verb = $Verb
239239
$this.Noun = $Noun
@@ -681,13 +681,95 @@ function New-OutputHandler {
681681
function New-CrescendoCommand {
682682
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions","")]
683683
param (
684-
[Parameter(Position=0,Mandatory=$true)][string]$Verb,
685-
[Parameter(Position=1,Mandatory=$true)][string]$Noun,
686-
[Parameter(Position=2)][string]$OriginalName
684+
[Parameter(Position=0,Mandatory=$true)]
685+
[ArgumentCompleter( {
686+
param ( $commandName,
687+
$parameterName,
688+
$wordToComplete,
689+
$commandAst,
690+
$fakeBoundParameters )
691+
if ($WordToComplete) {
692+
(Get-Verb).Verb | Where-Object { $_ -match "^$WordToComplete"}
693+
}
694+
695+
else {
696+
(Get-Verb).Verb
697+
}
698+
} )]
699+
[string]
700+
$Verb,
701+
702+
[Parameter(Position=1,Mandatory=$true)]
703+
[string]
704+
$Noun,
705+
706+
[Parameter(Position=2)]
707+
[string]
708+
$OriginalName,
709+
710+
[Parameter(Position=3)]
711+
[string]
712+
$Description,
713+
714+
[Parameter()]
715+
[string[]]
716+
$Aliases,
717+
718+
[Parameter()]
719+
[string] $DefaultParameterSetName,
720+
721+
[Parameter()]
722+
[bool]
723+
$SupportsShouldProcess,
724+
725+
[Parameter()]
726+
[string]
727+
$ConfirmImpact,
728+
729+
[Parameter()]
730+
[bool]
731+
$SupportsTransactions,
732+
733+
[Parameter()]
734+
[bool]
735+
$NoInvocation,
736+
# certain scenarios want to use the generated code as a front end. When true, the generated code will return the arguments only.
737+
[Parameter()]
738+
[UsageInfo]
739+
$Usage,
740+
741+
[Parameter()]
742+
[List[ParameterInfo]]
743+
$Parameters,
744+
745+
[Parameter()]
746+
[List[ExampleInfo]]
747+
$Examples,
748+
749+
[Parameter()]
750+
[string]
751+
$OriginalText,
752+
753+
[Parameter()]
754+
[string[]]
755+
$HelpLinks,
756+
757+
[Parameter()]
758+
[OutputHandler[]]
759+
$OutputHandlers
760+
761+
762+
687763
)
688-
$cmd = [Command]::new($Verb, $Noun)
689-
$cmd.OriginalName = $OriginalName
764+
765+
$cmd = [Command]::new($Verb, $Noun,$OriginalName,$Description)
766+
767+
$PSBoundParameters.GetEnumerator() |
768+
ForEach-Object {
769+
$cmd.$($psitem.Key) = $PSItem.Value
770+
}
690771
$cmd
772+
691773
}
692774

693775
function Export-CrescendoCommand {

0 commit comments

Comments
 (0)