Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow enable disable off all aliases #33

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions InvokeHelperTest/public/InvokeCommandList.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 22 additions & 8 deletions public/InvokeCommandList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@
[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

<#
Expand All @@ -118,9 +115,26 @@
[Parameter()][string]$Tag
)

Set-IncokeCommandAlias -Tag $Tag -Value $true

} Export-ModuleMember -Function Enable-InvokeCommandAlias

function Set-IncokeCommandAlias{

Check warning

Code scanning / PSScriptAnalyzer

Function 'Set-IncokeCommandAlias' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Set-IncokeCommandAlias' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[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
}
Loading