Skip to content
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
29 changes: 29 additions & 0 deletions InvokeHelperTest/public/InvokeCommandList.test.ps1
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 10 additions & 2 deletions en-US/about_InvokeHelper.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 14 additions & 2 deletions public/InvokeCommandList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ function Set-InvokeCommandAlias{
}
} Export-ModuleMember -Function Set-InvokeCommandAlias

function Get-InvokeCommandAlias{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-InvokeCommandAlias' does not have a help comment.

The cmdlet 'Get-InvokeCommandAlias' does not have a help comment.
[CmdletBinding(SupportsShouldProcess)]

Check warning

Code scanning / PSScriptAnalyzer

'Get-InvokeCommandAlias' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue.

'Get-InvokeCommandAlias' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue.
param()

if($script:InvokeCommandList -eq $null -or $script:InvokeCommandList.Count -eq 0){
return $null
} else {
return $script:InvokeCommandList

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-InvokeCommandAlias' returns an object of type 'System.Collections.Hashtable' but this type is not declared in the OutputType attribute.

The cmdlet 'Get-InvokeCommandAlias' returns an object of type 'System.Collections.Hashtable' but this type is not declared in the OutputType attribute.
}

} Export-ModuleMember -Function Get-InvokeCommandAlias

function Test-InvokeCommandAlias{
[CmdletBinding()]
param(
Expand Down Expand Up @@ -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
Expand Down