diff --git a/InvokeHelperTest/public/InvokeCommandList.test.ps1 b/InvokeHelperTest/public/InvokeCommandList.test.ps1 index 73cd757..0bd9bc5 100644 --- a/InvokeHelperTest/public/InvokeCommandList.test.ps1 +++ b/InvokeHelperTest/public/InvokeCommandList.test.ps1 @@ -9,6 +9,25 @@ function InvokeHelperTest_InvokeCommandAlias_Get{ Assert-AreEqual -Expected 'echo "this is a sample command2"' -Presented $result["commandAlias2"].Command } +function InvokeHelperTest_InvokeCommandAlias_Get_With_Tag{ + + Set-InvokeCommandAlias -Alias "commandAlias" -Command 'echo "this is a sample command"' -Tag Module1 + Set-InvokeCommandAlias -Alias "commandAlias2" -Command 'echo "this is a sample command2"' -Tag Module2 + + $result = Get-InvokeCommandAliasList -Tag Module1 + + Assert-AreEqual -Expected 'echo "this is a sample command"' -Presented $result["commandAlias"].Command + + Set-InvokeCommandAlias -Alias "commandAlias3" -Command 'echo "this is a sample command3"' -Tag Module1 + + $result = Get-InvokeCommandAliasList -Tag Module1 + + Assert-Count -Expected 2 -Presented $result + Assert-AreEqual -Expected 'echo "this is a sample command"' -Presented $result["commandAlias"].Command + Assert-AreEqual -Expected 'echo "this is a sample command3"' -Presented $result["commandAlias3"].Command + +} + function InvokeHelperTest_InvokeCommandAlias_Reset{ Reset-InvokeCommandAlias diff --git a/public/InvokeCommandList.ps1 b/public/InvokeCommandList.ps1 index 8b62e9e..f11a04a 100644 --- a/public/InvokeCommandList.ps1 +++ b/public/InvokeCommandList.ps1 @@ -31,14 +31,25 @@ Get the Command list active in the module function Get-InvokeCommandAliasList{ [CmdletBinding()] [OutputType([hashtable])] - param() + param( + [Parameter()][string]$Tag + ) if($script:InvokeCommandList -eq $null -or $script:InvokeCommandList.Count -eq 0){ return $null + } + + $ret = @{} + + if(-Not [string]::IsNullOrWhiteSpace($Tag)){ + $validKeys = $script:InvokeCommandList.Keys | Where-Object { $script:InvokeCommandList.$_.Tag -eq $Tag } + $validKeys | ForEach-Object { $ret.$_ = $script:InvokeCommandList.$_ } } else { - return $script:InvokeCommandList + $ret = $script:InvokeCommandList } + return $ret + } Export-ModuleMember -Function Get-InvokeCommandAliasList function Test-InvokeCommandAlias{