From 5a451066db866a84593f7b62ba6c0cd1374f3dfc Mon Sep 17 00:00:00 2001 From: rulasg Date: Sat, 3 Feb 2024 09:23:47 +0100 Subject: [PATCH] allow enable disable off all aliases Fixes #32 --- .../public/InvokeCommandList.test.ps1 | 50 +++++++++++++++++++ public/InvokeCommandList.ps1 | 30 ++++++++--- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/InvokeHelperTest/public/InvokeCommandList.test.ps1 b/InvokeHelperTest/public/InvokeCommandList.test.ps1 index e69e985..73cd757 100644 --- a/InvokeHelperTest/public/InvokeCommandList.test.ps1 +++ b/InvokeHelperTest/public/InvokeCommandList.test.ps1 @@ -83,6 +83,56 @@ function InvokeHelperTest_InvokeCommandAlias_Enable_Disable{ Assert-IsTrue -Condition $result.commandAlias4.Enabled } +function InvokeHelperTest_InvokeCommandAlias_Enable_Disable_All_Case{ + + Set-InvokeCommandAlias -Alias "commandAlias1" -Command "echo $text1" -Tag Mock1 + Set-InvokeCommandAlias -Alias "commandAlias2" -Command "echo $text2" -Tag Mock2 + Set-InvokeCommandAlias -Alias "commandAlias3" -Command "echo $text3" -Tag Mock1 + Set-InvokeCommandAlias -Alias "commandAlias4" -Command "echo $text4" -Tag Mock2 + + Disable-InvokeCommandAlias -Tag moCK1 + + $result = Get-InvokeCommandAliasList + + Assert-IsFalse -Condition $result.commandAlias1.Enabled + Assert-IsFalse -Condition $result.commandAlias3.Enabled + + Assert-IsTrue -Condition $result.commandAlias2.Enabled + Assert-IsTrue -Condition $result.commandAlias4.Enabled + + Enable-InvokeCommandAlias -Tag ALL + + Assert-IsTrue -Condition $result.commandAlias1.Enabled + Assert-IsTrue -Condition $result.commandAlias3.Enabled + + Assert-IsTrue -Condition $result.commandAlias2.Enabled + Assert-IsTrue -Condition $result.commandAlias4.Enabled + + Disable-InvokeCommandAlias -Tag * + + Assert-IsFalse -Condition $result.commandAlias1.Enabled + Assert-IsFalse -Condition $result.commandAlias3.Enabled + + Assert-IsFalse -Condition $result.commandAlias2.Enabled + Assert-IsFalse -Condition $result.commandAlias4.Enabled + + Enable-InvokeCommandAlias -Tag * + + Assert-IsTrue -Condition $result.commandAlias1.Enabled + Assert-IsTrue -Condition $result.commandAlias3.Enabled + + Assert-IsTrue -Condition $result.commandAlias2.Enabled + Assert-IsTrue -Condition $result.commandAlias4.Enabled + + Disable-InvokeCommandAlias -Tag aLl + + Assert-IsFalse -Condition $result.commandAlias1.Enabled + Assert-IsFalse -Condition $result.commandAlias3.Enabled + + Assert-IsFalse -Condition $result.commandAlias2.Enabled + Assert-IsFalse -Condition $result.commandAlias4.Enabled +} + function InvokeHelperTest_InvokeCommandAlias_Invoke_Enable_Disable{ $text1 = "this is a sample command 1" diff --git a/public/InvokeCommandList.ps1 b/public/InvokeCommandList.ps1 index c45ba24..dd46568 100644 --- a/public/InvokeCommandList.ps1 +++ b/public/InvokeCommandList.ps1 @@ -101,11 +101,8 @@ function Disable-InvokeCommandAlias{ [Parameter()][string]$Tag ) - Foreach ($key in $InvokeCommandList.Keys) { - if($InvokeCommandList[$key].Tag -eq $Tag){ - $InvokeCommandList[$key].Enabled = $false - } - } + Set-IncokeCommandAlias -Tag $Tag -Value $false + } Export-ModuleMember -Function Disable-InvokeCommandAlias <# @@ -118,9 +115,26 @@ function Enable-InvokeCommandAlias{ [Parameter()][string]$Tag ) + Set-IncokeCommandAlias -Tag $Tag -Value $true + +} Export-ModuleMember -Function Enable-InvokeCommandAlias + +function Set-IncokeCommandAlias{ + [CmdletBinding()] + param( + [Parameter(Mandatory)][string]$Tag, + [Parameter(Mandatory)][bool]$Value + ) + Foreach ($key in $InvokeCommandList.Keys) { - if($InvokeCommandList[$key].Tag -eq $Tag){ - $InvokeCommandList[$key].Enabled = $true + $tag = $Tag.ToLower() + $aliasTag = $InvokeCommandList[$key].Tag.ToLower() + + $sameTag = $tag -eq $aliasTag + $alltags = $tag.ToLower() -eq "all" -or $tag -eq "*" + + if($sameTag -or $alltags){ + $InvokeCommandList[$key].Enabled = $Value } } -} Export-ModuleMember -Function Enable-InvokeCommandAlias \ No newline at end of file +} \ No newline at end of file