Skip to content

Commit

Permalink
✨ (#376) [Show-Karma] Enable -Contemplate with -Topic (#377)
Browse files Browse the repository at this point in the history
* ✨ Enable -Contemplate with -Topic

* ✅ add test

* 📝 update docs

* 🔧 Correctly compare topic input

Wildcards are supposed to be supported, so we should expect wildcards.

* 📝 Adjust params order in documentation

Required parameters should be shown first, and actually shown as required.
  • Loading branch information
vexx32 committed Mar 10, 2020
1 parent e3b7347 commit 2fd7167
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion PSKoans/Public/Show-Karma.ps1
Expand Up @@ -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()]
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Tests/Functions/Public/Show-Karma.Tests.ps1
Expand Up @@ -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'

Expand Down
28 changes: 18 additions & 10 deletions docs/Show-Karma.md
Expand Up @@ -17,29 +17,29 @@ Reflect on your progress and check your answers.
Show-Karma [-Topic <String[]>] [-ClearScreen] [-Detailed] [<CommonParameters>]
```

### IncludeModule
### OpenFile
```
Show-Karma [-Topic <String[]>] -IncludeModule <String[]> [-ClearScreen] [-Detailed] [<CommonParameters>]
Show-Karma -Contemplate [-Topic <String[]>] [-ClearScreen] [<CommonParameters>]
```

### ModuleOnly
### IncludeModule
```
Show-Karma [-Topic <String[]>] -Module <String[]> [-ClearScreen] [-Detailed] [<CommonParameters>]
Show-Karma -IncludeModule <String[]> [-Topic <String[]>] [-ClearScreen] [-Detailed] [<CommonParameters>]
```

### ListKoans
### ModuleOnly
```
Show-Karma [-Topic <String[]>] [-Module <String[]>] [-List] [-ClearScreen] [<CommonParameters>]
Show-Karma -Module <String[]> [-Topic <String[]>] [-ClearScreen] [-Detailed] [<CommonParameters>]
```

### OpenFile
### ListKoans
```
Show-Karma [-Contemplate] [-ClearScreen] [<CommonParameters>]
Show-Karma -List [-Topic <String[]>] [-Module <String[]>] [-ClearScreen] [<CommonParameters>]
```

### OpenFolder
```
Show-Karma [-Library] [-ClearScreen] [<CommonParameters>]
Show-Karma -Library [-ClearScreen] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fd7167

Please sign in to comment.