Skip to content

Commit

Permalink
Add -Detailed parameter for Measure-Karma (#166)
Browse files Browse the repository at this point in the history
* ✨ Add -Results for Show-MeditationPrompt
Allows the full test results for a file to be passed in.
♻️ Some minor adjustments to the default prompt display as well.

* ✨ add -Detailed param for Measure-Karma
Causes the latest file's results to be sent to the meditation prompt.
Prompt will display a summary of the current file's tests.

* ♻️ Restrict -Detailed to default param set.

* 📝 Update markdown docs

* 📝 Update external help
  • Loading branch information
vexx32 committed May 4, 2019
1 parent 0d705de commit 757d80d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 32 deletions.
9 changes: 6 additions & 3 deletions PSKoans/Data/Show-MeditationPrompt.Data.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
Welcome, seeker of enlightenment.
Please wait a moment while we examine your karma...
"@
DetailEntry = @"
{0} It {1}
"@
Describe = @"
Describing '{0}' has damaged your karma.
Expand All @@ -21,8 +24,8 @@ Describing '{0}' has damaged your karma.
"@
Subject = @"
[It] {0}
{1}
{0} It {1}
{2}
"@
Koan = @"
Expand Down Expand Up @@ -162,4 +165,4 @@ Choosing to raise a goose in a bottle,
How will you get it out once it is grown?
'@
)
}
}
27 changes: 24 additions & 3 deletions PSKoans/Private/Show-MeditationPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ function Show-MeditationPrompt {

[Parameter()]
[string[]]
$RequestedTopic
$RequestedTopic,

[Parameter()]
[PSObject[]]
$Results
)
begin {
$Red = @{ForegroundColor = 'Red' }
$Blue = @{ForegroundColor = 'Cyan' }
$White = @{ForegroundColor = 'Yellow' }
$Green = @{ForegroundColor = 'Green' }

$Koan = (Get-Random -InputObject $script:MeditationStrings) -replace '^|\r?(\n)', ('$1 {0} ' -f [char]0x258c)
$TopicList = ($RequestedTopic -join "`n - ")

Expand All @@ -108,7 +114,7 @@ function Show-MeditationPrompt {
Write-Host @Red $Expectation

Write-Host @Blue $script:MeditationPrompts['Meditate']
Write-Host @Red ($script:MeditationPrompts['Subject'] -f $ItName, $Meditation)
Write-Host @Red ($script:MeditationPrompts['Subject'] -f [char]0xd7, $ItName, $Meditation)

Write-Host @White ($script:MeditationPrompts['Koan'] -f $Koan)

Expand All @@ -135,14 +141,29 @@ function Show-MeditationPrompt {
[int] $PortionDone = ($CurrentTopic['Completed'] / $CurrentTopic['Total']) * $TopicProgressWidth

$ProgressBar = " [{3}]: [{0}{1}] {2}" -f @(
"$([char]0x25b0)" * $PortionDone
"$([char]0x25a0)" * $PortionDone
"$([char]0x2015)" * ($TopicProgressWidth - $PortionDone)
$TopicProgressAmount
$CurrentTopic['Name']
)
Write-Host $ProgressBar @Blue
}
#endregion TopicProgressBar
Write-Host

if ($PSBoundParameters.ContainsKey('Results')) {
foreach ($KoanResult in $Results) {
$Params = @{
Object = $script:MeditationPrompts['DetailEntry'] -f @(
if ($KoanResult.Passed) { [char]0x25b8 } else { [char]0xd7 }
$KoanResult.Name
)
}
$Params += if ($KoanResult.Passed) { $Green } else { $Red }
Write-Host @Params
}
}

Write-Host
#region TotalProgressBar
[int] $PortionDone = ($KoansPassed / $TotalKoans) * $ProgressWidth
Expand Down
19 changes: 14 additions & 5 deletions PSKoans/Public/Measure-Karma.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Measure-Karma {
[CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = "Default",
[CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'Default',
HelpUri = 'https://github.com/vexx32/PSKoans/tree/master/docs/Measure-Karma.md')]
[OutputType([void])]
[Alias('Invoke-PSKoans', 'Test-Koans', 'Get-Enlightenment', 'Meditate', 'Clear-Path')]
Expand Down Expand Up @@ -40,7 +40,12 @@
[Parameter()]
[Alias()]
[switch]
$ClearScreen
$ClearScreen,

[Parameter(ParameterSetName = 'Default')]
[Alias()]
[switch]
$Detailed
)
switch ($PSCmdlet.ParameterSetName) {
'ListKoans' {
Expand Down Expand Up @@ -143,12 +148,12 @@
}
}

if ($PesterTests.FailedCount -gt 0) {
$Meditation = if ($PesterTests.FailedCount -gt 0) {
$NextKoanFailed = $PesterTests.TestResult |
Where-Object Result -eq 'Failed' |
Select-Object -First 1

$Meditation = @{
@{
DescribeName = $NextKoanFailed.Describe
Expectation = $NextKoanFailed.ErrorRecord
ItName = $NextKoanFailed.Name
Expand All @@ -163,13 +168,17 @@
}
}
else {
$Meditation = @{
@{
Complete = $true
KoansPassed = $KoansPassed
TotalKoans = $PesterTests.TotalCount
}
}

if ($Detailed) {
$Meditation.Add('Results', $PesterTests.TestResult)
}

if ($PSBoundParameters.ContainsKey('Topic')) {
$Meditation.Add('RequestedTopic', $Topic)
}
Expand Down
63 changes: 43 additions & 20 deletions PSKoans/en-us/PSKoans-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,30 @@ C:\Users\Timmy\PSKoans</dev:code>
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="ListKoans">
<maml:name>ListTopics</maml:name>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Detailed</maml:name>
<maml:Description>
<maml:para>Output a complete list of available koan topics.</maml:para>
<maml:para>Adds a summarized view of the current topic file to the meditation prompt. The summary will contain a full list of all koans in the file, and indicate their current status.</maml:para>
</maml:Description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="Koan, File">
<maml:name>Topic</maml:name>
<maml:Description>
<maml:para>Execute koans only from the selected Topic(s). Regex patterns are permitted.</maml:para>
<maml:para>If combined with `-Reset`, the specified topics are reset to their initial states.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:Description>
Expand Down Expand Up @@ -238,31 +251,17 @@ C:\Users\Timmy\PSKoans</dev:code>
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Reset</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="ListKoans">
<maml:name>ListTopics</maml:name>
<maml:Description>
<maml:para>Resets everything in your local koan folder to the initial state. Use with caution. This can be used after using `Set-PSKoanLocation` to a new directory to get started.</maml:para>
<maml:para>If combined with `-Topic`, resets only the specified topics.</maml:para>
<maml:para>Output a complete list of available koan topics.</maml:para>
</maml:Description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="Koan, File">
<maml:name>Topic</maml:name>
<maml:Description>
<maml:para>Execute koans only from the selected Topic(s). Regex patterns are permitted.</maml:para>
<maml:para>If combined with `-Reset`, the specified topics are reset to their initial states.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:Description>
Expand Down Expand Up @@ -299,6 +298,18 @@ C:\Users\Timmy\PSKoans</dev:code>
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Reset</maml:name>
<maml:Description>
<maml:para>Resets everything in your local koan folder to the initial state. Use with caution. This can be used after using `Set-PSKoanLocation` to a new directory to get started.</maml:para>
<maml:para>If combined with `-Topic`, resets only the specified topics.</maml:para>
</maml:Description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="Koan, File">
<maml:name>Topic</maml:name>
<maml:Description>
Expand Down Expand Up @@ -362,6 +373,18 @@ C:\Users\Timmy\PSKoans</dev:code>
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Detailed</maml:name>
<maml:Description>
<maml:para>Adds a summarized view of the current topic file to the meditation prompt. The summary will contain a full list of all koans in the file, and indicate their current status.</maml:para>
</maml:Description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="ListKoans">
<maml:name>ListTopics</maml:name>
<maml:Description>
Expand Down
18 changes: 17 additions & 1 deletion docs/Measure-Karma.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Reflect on your progress and check your answers.

### Default (Default)
```
Measure-Karma [-Topic <String[]>] [-ClearScreen] [-WhatIf] [-Confirm] [<CommonParameters>]
Measure-Karma [-Topic <String[]>] [-ClearScreen] [-Detailed] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### Reset
Expand Down Expand Up @@ -99,6 +99,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Detailed
Adds a summarized view of the current topic file to the meditation prompt.
The summary will contain a full list of all koans in the file, and indicate their current status.

```yaml
Type: SwitchParameter
Parameter Sets: Default
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ListTopics
Output a complete list of available koan topics.

Expand Down

0 comments on commit 757d80d

Please sign in to comment.