diff --git a/InvokeHelperTest/public/InvokeCommandList.test.ps1 b/InvokeHelperTest/public/InvokeCommandList.test.ps1 new file mode 100644 index 0000000..905db7e --- /dev/null +++ b/InvokeHelperTest/public/InvokeCommandList.test.ps1 @@ -0,0 +1,29 @@ +function InvokeHelperTest_InvokeCommandAlias_Get{ + + Set-InvokeCommandAlias -Alias "commandAlias" -Command 'echo "this is a sample command"' + Set-InvokeCommandAlias -Alias "commandAlias2" -Command 'echo "this is a sample command2"' + + $result = Get-InvokeCommandAlias + + Assert-AreEqual -Expected 'echo "this is a sample command"' -Presented $result["commandAlias"] + Assert-AreEqual -Expected 'echo "this is a sample command2"' -Presented $result["commandAlias2"] +} + +function InvokeHelperTest_InvokeCommandAlias_Reset{ + + Reset-InvokeCommandAlias + + $result = Get-InvokeCommandAlias + Assert-IsNull -Object $result + + Set-InvokeCommandAlias -Alias "commandAlias" -Command 'echo "this is a sample command"' + Set-InvokeCommandAlias -Alias "commandAlias2" -Command 'echo "this is a sample command2"' + + $result = Get-InvokeCommandAlias + Assert-AreEqual -Expected 'echo "this is a sample command"' -Presented $result["commandAlias"] + Assert-AreEqual -Expected 'echo "this is a sample command2"' -Presented $result["commandAlias2"] + + Reset-InvokeCommandAlias + $result = Get-InvokeCommandAlias + Assert-IsNull -Object $result +} \ No newline at end of file diff --git a/en-US/about_InvokeHelper.help.txt b/en-US/about_InvokeHelper.help.txt index abe6f06..7c3641d 100644 --- a/en-US/about_InvokeHelper.help.txt +++ b/en-US/about_InvokeHelper.help.txt @@ -29,12 +29,20 @@ SETTING THE COMMAND LIST To allow the decouple of the function with the app or tool to call we can set the command list for later to be used. ```powershell - > Set-InvokeCommandAlias -Alias "GetUser" -CommandPath "gh api user" + > Set-InvokeCommandAlias -Alias "GetUser" -Command "gh api user" > $result = Invoke-MyCommandJson -Command "GetUser" - > Assert-AreEqual -Expected 'fakeName' -Presented $result.login + > Assert-AreEqual -Expected 'myHandle' -Presented $result.login > Assert-AreEqual -Expected 6666666 -Presented $result.id ``` + ```powershell + > Get-InvokeCommandAlias + + Name Value + ---- ----- + GetUser gh api user + ``` + PARAMETERS If the command have variables like `{name}` you can use the $Parameters parameter to input a HASTABLE that describes all the strings that will be replaced on the command before executing it. Combining $Parameters and CommandsList you will be able to decouple the tool calls from your code for later Unit Testing or changing tool easylly. \ No newline at end of file diff --git a/public/InvokeCommandList.ps1 b/public/InvokeCommandList.ps1 index 7a7a033..e2b86d6 100644 --- a/public/InvokeCommandList.ps1 +++ b/public/InvokeCommandList.ps1 @@ -18,6 +18,18 @@ function Set-InvokeCommandAlias{ } } Export-ModuleMember -Function Set-InvokeCommandAlias +function Get-InvokeCommandAlias{ + [CmdletBinding(SupportsShouldProcess)] + param() + + if($script:InvokeCommandList -eq $null -or $script:InvokeCommandList.Count -eq 0){ + return $null + } else { + return $script:InvokeCommandList + } + +} Export-ModuleMember -Function Get-InvokeCommandAlias + function Test-InvokeCommandAlias{ [CmdletBinding()] param( @@ -55,10 +67,10 @@ function Reset-InvokeCommandAlias{ param() process { if ($PSCmdlet.ShouldProcess("CommandList", "Reset")) { - $InvokeCommandList = @{} + $script:InvokeCommandList = @{} } - "$InvokeCommandList" | Write-Verbose + "$script:InvokeCommandList" | Write-Verbose } } Export-ModuleMember -Function Reset-InvokeCommandAlias