Skip to content

Commit

Permalink
Remove dynamic param and use ArgumentCompleter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Jan 12, 2025
1 parent 9ef1942 commit a695191
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
21 changes: 1 addition & 20 deletions src/functions/public/Install-NerdFont.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules Admin, Fonts, DynamicParams
#Requires -Modules Admin, Fonts

function Install-NerdFont {
<#
Expand Down Expand Up @@ -38,25 +38,6 @@ function Install-NerdFont {
[Scope] $Scope = 'CurrentUser'
)

dynamicparam {
$DynamicParamDictionary = New-DynamicParamDictionary

$dynPath = @{
Name = 'Name'
Type = [string[]]
Mandatory = $true
ParameterSetName = 'Name'
HelpMessage = 'Name of the font to install.'
ValueFromPipeline = $true
ValueFromPipelineByPropertyName = $true
ValidateSet = Get-NerdFonts | Select-Object -ExpandProperty Name
DynamicParamDictionary = $DynamicParamDictionary
}
New-DynamicParam @dynPath

return $DynamicParamDictionary
}

begin {
if ($Scope -eq 'AllUsers' -and -not (IsAdmin)) {
$errorMessage = @'
Expand Down
8 changes: 8 additions & 0 deletions src/functions/public/completers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Register-ArgumentCompleter -CommandName Install-NerdFont, Get-NerdFont -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter

Get-NerdFont | Where-Object { $_.Name -like $wordToComplete } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name)
}
}

0 comments on commit a695191

Please sign in to comment.