From 89e9b9fc552b85190e8dd95594a365b79f2bd0a0 Mon Sep 17 00:00:00 2001 From: ddemeyer Date: Tue, 23 Jan 2024 20:38:29 +0100 Subject: [PATCH] #153 Extend Parameter Completion for *-IshSetting cmdlets parameter -FieldName, similar like Get-IshMetadataField or Get-IshLovValue --- .../Scripts/Public/Expand-ISHParameter.ps1 | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Scripts/Public/Expand-ISHParameter.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Scripts/Public/Expand-ISHParameter.ps1 index b4fe2e7c..4914c10f 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Scripts/Public/Expand-ISHParameter.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Scripts/Public/Expand-ISHParameter.ps1 @@ -81,3 +81,28 @@ Register-IshAuxParameterCompleter -CommandName 'Set-IshMetadataField' -Parameter Register-IshAuxParameterCompleter -CommandName 'Set-IshMetadataFilterField' -ParameterName 'Name' -ScriptBlock $fieldName Register-IshAuxParameterCompleter -CommandName 'Set-IshRequestedMetadataField' -ParameterName 'Name' -ScriptBlock $fieldName Register-IshAuxParameterCompleter -CommandName 'Set-IshRequiredCurrentMetadataField' -ParameterName 'Name' -ScriptBlock $fieldName + + +Write-Debug ("[" + $MyInvocation.MyCommand + "] Parameter binding for *-*FieldName (field names)") +$fieldName = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $ishSession = Get-IshAuxSessionState -Name "ISHRemoteSessionStateIshSession" + if (($null -ne $fakeBoundParameter['IshSession']) -And ($fakeBoundParameter['IshSession'].GetType().Name -eq 'IshSession') -And ($fakeBoundParameter['IshSession'].IshTypeFieldDefinition.Count -gt 0)) + { + # Explicit -IshSession takes precedence over SessionState one + $ishSession = $fakeBoundParameter['IshSession'] + } + if ($ishSession -ne $null) + { + # TODO [Could] Expand parameter could take -Level into account to filter even more + $ishSession.IshTypeFieldDefinition | + Where-Object { ($_.ISHType -eq 'ISHConfiguration') -and ($_.Name -like "$wordToComplete*") } | + Sort-Object -Unique Name | + + # Creation with ToolTips is often too slow, causing Ctrl-Space actions to fall back to file system suggestion + # ForEach-Object { New-IshAuxCompletionResult -CompletionText $_.Name -ToolTip ($_.Name + " (" + $_.Type + ") - " + $_.Description ) } + ForEach-Object { New-IshAuxCompletionResult -CompletionText $_.Name } + } +} +Register-IshAuxParameterCompleter -CommandName 'Get-IshSetting' -ParameterName 'FieldName' -ScriptBlock $fieldName +Register-IshAuxParameterCompleter -CommandName 'Set-IshSetting' -ParameterName 'FieldName' -ScriptBlock $fieldName \ No newline at end of file