diff --git a/PSKoans/Public/Show-Karma.ps1 b/PSKoans/Public/Show-Karma.ps1 index f16600724..de305ff37 100644 --- a/PSKoans/Public/Show-Karma.ps1 +++ b/PSKoans/Public/Show-Karma.ps1 @@ -7,6 +7,7 @@ function Show-Karma { [Parameter(ParameterSetName = 'ListKoans')] [Parameter(ParameterSetName = 'ModuleOnly')] [Parameter(ParameterSetName = 'IncludeModule')] + [Parameter(ParameterSetName = 'OpenFile')] [Parameter(ParameterSetName = 'Default')] [Alias('Koan', 'File')] [SupportsWildcards()] @@ -87,7 +88,7 @@ function Show-Karma { } 'OpenFile' { # If there is no cached data, we need to call Get-Karma to populate it - if (-not $script:CurrentTopic) { + if (-not $script:CurrentTopic -or ($Topic -and $script:CurrentTopic.Name -notlike $Topic)) { try { # We can discard this; the results we need are saved in $script:CurrentTopic $null = Get-Karma @GetParams diff --git a/Tests/Functions/Public/Show-Karma.Tests.ps1 b/Tests/Functions/Public/Show-Karma.Tests.ps1 index 5a6f24c11..8cd01a066 100644 --- a/Tests/Functions/Public/Show-Karma.Tests.ps1 +++ b/Tests/Functions/Public/Show-Karma.Tests.ps1 @@ -281,6 +281,18 @@ Describe 'Show-Karma' { $script:CurrentTopic | Should -BeNullOrEmpty } + It 'opens the specified -Topic in the selected editor' { + Set-PSKoanSetting -Name Editor -Value 'code' + $Result = Show-Karma -Contemplate -Topic TestTopic + + $Result.Arguments[1] | Should -MatchExactly ([regex]::Escape($TestFile.FullName)) + + Assert-MockCalled Get-Command -Times 1 + Assert-MockCalled Start-Process -Times 1 + + $script:CurrentTopic | Should -BeNullOrEmpty + } + It 'invokes the set editor with unknown editor chosen' { Set-PSKoanSetting -Name Editor -Value 'vim' diff --git a/docs/Show-Karma.md b/docs/Show-Karma.md index 228a9f80f..94ad920ba 100644 --- a/docs/Show-Karma.md +++ b/docs/Show-Karma.md @@ -17,29 +17,29 @@ Reflect on your progress and check your answers. Show-Karma [-Topic ] [-ClearScreen] [-Detailed] [] ``` -### IncludeModule +### OpenFile ``` -Show-Karma [-Topic ] -IncludeModule [-ClearScreen] [-Detailed] [] +Show-Karma -Contemplate [-Topic ] [-ClearScreen] [] ``` -### ModuleOnly +### IncludeModule ``` -Show-Karma [-Topic ] -Module [-ClearScreen] [-Detailed] [] +Show-Karma -IncludeModule [-Topic ] [-ClearScreen] [-Detailed] [] ``` -### ListKoans +### ModuleOnly ``` -Show-Karma [-Topic ] [-Module ] [-List] [-ClearScreen] [] +Show-Karma -Module [-Topic ] [-ClearScreen] [-Detailed] [] ``` -### OpenFile +### ListKoans ``` -Show-Karma [-Contemplate] [-ClearScreen] [] +Show-Karma -List [-Topic ] [-Module ] [-ClearScreen] [] ``` ### OpenFolder ``` -Show-Karma [-Library] [-ClearScreen] [] +Show-Karma -Library [-ClearScreen] [] ``` ## DESCRIPTION @@ -64,6 +64,13 @@ Use [`Set-PSKoanSetting`](./Set-PSKoanSetting.md) to change the editor used. If a known editor (`code`, `code-insiders`, or `atom`) is used, PSKoans will pass along line information as well. +### EXAMPLE 3 +```powershell +Show-Karma -Contemplate -Topic AboutComparison +``` + +Opens the specified `AboutComparison` topic file in the preferred editor. + ## PARAMETERS ### -ClearScreen @@ -195,10 +202,11 @@ Accept wildcard characters: False ### -Topic Execute koans only from the selected Topic(s). Wildcard patterns are permitted. +When provided along with `-Contemplate`, the targeted topic will be respected. ```yaml Type: String[] -Parameter Sets: Default, IncludeModule, ModuleOnly, ListKoans +Parameter Sets: Default, OpenFile, IncludeModule, ModuleOnly, ListKoans Aliases: Koan, File Required: False