Update powershell_completions.go

Incorporate @bartoncasey insight about typical alias usage in https://github.com/spf13/cobra/pull/2049
This commit is contained in:
Mavaddat Javid 2023-10-29 17:00:24 -04:00 committed by GitHub
parent f43b653d17
commit caeed9f2a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -279,12 +279,12 @@ filter __%[1]s_escapeStringWithSpecialChars {
} }
} }
# Enumerate the cmds for %[1]s (set by System.Environment) # Enumerate the cmds for %[1]s (set by System.Environment)
$available%[2]s = Get-Command -Name '%[1]s' -All -ErrorAction SilentlyContinue $available%[2]s = Get-Command -Name '%[1]s' -All -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition -ErrorAction SilentlyContinue
# Enumerate extant aliases for %[1]s (already set by user) # Enumerate extant aliases for %[1]s (already set by user)
${__%[2]sAliases} = @() ${__%[2]sAliases} = @()
foreach($__%[2]sCmd in $available%[2]s){ foreach($__%[2]sCmd in $available%[2]s){
$__%[2]sAliases += Get-Alias | Where-Object { $_.Definition -eq ($__%[2]sCmd | Resolve-Path) } $__%[2]sAliases += Get-Alias | Where-Object { $_ -eq ($__%[2]sCmd | Resolve-Path) -or $_ -eq (Get-Command -Name $_ -ErrorAction SilentlyContinue).Definition}
} }
# Register args completer for all cmds and aliases # Register args completer for all cmds and aliases
[string[]]$joint%[2]snames = [array]$available%[2]s.Name + [array]${__%[2]sAliases}.Name + @('%[1]s') [string[]]$joint%[2]snames = [array]$available%[2]s.Name + [array]${__%[2]sAliases}.Name + @('%[1]s')