ps/Modules/.build/Get-Aliases.ps1
2023-05-30 22:51:22 -07:00

42 lines
1.6 KiB
PowerShell

Function Get-Aliases {
<#
.SYNOPSIS
Collects all alias names from files in a folder. Assumes Test-FunctionNames properly ran and validated target function names.
.EXAMPLE
Get-Aliases .\Alkami.PowerShell.IIS\Public
.PARAMETER FolderPath
The name of the folder to examine all files under.
#>
[CmdletBinding()]
Param (
[String]$FolderPath
)
process {
$aliases = @()
$verbs = Get-Verb | Select-Object -ExpandProperty Verb
$files = (Get-ChildItem -Path $FolderPath *.ps1)
foreach($file in $files) {
if ($file.BaseName.ToLower().EndsWith(".tests") -or $file.BaseName.ToLower().EndsWith(".test")) {
Write-Verbose "skipping function names of test $file"
} else {
$lines = (Get-Content $file.FullName)
foreach($line in $lines) {
if (($line.Trim().ToLower().StartsWith("set-alias")) -or ($line.Trim().ToLower().StartsWith("new-alias"))) {
$candidateLine = $line -replace ';','' -replace '-name','' -replace '-value','' -replace '-force','' -replace '-scope:global','' -replace '-Scope Global',''
$splits = ($candidateLine.Trim() -split '\s+')
if ($splits.length -ne 3) {
Write-Warning "Could not parse line [$line] for Set-Alias, found [$splits]"
} else {
$aliases += $splits[1]
}
}
}
}
}
return $aliases
}
}