Skip to content

Commit c197985

Browse files
Gilbert SanchezHeyItsGilbert
authored andcommitted
feat(PesterExplorer): ✨ add detailed comment-based help for functions
* Added comment-based help to several functions to improve documentation. * Enhanced user experience for new contributors by providing clear usage examples. * Updated `CHANGELOG.md` to reflect these additions.
1 parent 233581e commit c197985

14 files changed

+339
-22
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
mode: 'ask'
3+
---
4+
This project uses PwshSpectreConsole and Pester to render a TUI for Pester
5+
results.The TUI allows users to navigate through Pester run results, viewing
6+
details of containers, blocks, and tests.
7+
8+
All suggestions should try to stay with 80 characters or 120 max. Use splatting
9+
when possible. You can create new lines after `|` to make it more readable.
10+
11+
# Examples
12+
You can use the following when you create `.EXAMPLE` text for the comment based
13+
help. All Object parameters will use the $run variable from the following code:
14+
15+
```
16+
$run = Invoke-Pester -Path 'tests' -PassThru
17+
```
18+
19+
# Example 1
20+
```powershell
21+
$run = Invoke-Pester -Path 'tests' -PassThru
22+
$run | Show-PesterResults
23+
```
24+
25+
An explanation of the example should be provided in the `.EXAMPLE` section with
26+
an empty line between the example and the explanation.
27+
28+
# PowerShell Functions
29+
All functions should have a `[CmdletBinding()]` attribute.

.markdownlint.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"MD013": false,
3+
"MD024": {
4+
"siblings_only": true
5+
}
6+
}

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
### Added
11+
12+
- Added comment based help on private functions to make it easier for new
13+
contributors to grok.
14+
1015
### Changed
1116

1217
- The `Show-PesterResult` List panel now the files using relative path from the
1318
current directory. It also added padding on the selected item as well as an
1419
additional icon to show the highlight.
20+
- Formatted all the functions to stay under 80 character line limit. This is a
21+
preference. We will have a 120 hard limit (when possible).
1522

1623
### Fixed
1724

1825
- Removed extra item from the stack that tracked which layer of the view you
1926
were in.
2027

21-
2228
## [0.1.0] Initial Version
2329

2430
### Added

PesterExplorer/Private/Format-PesterObjectName.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
function Format-PesterObjectName {
2+
<#
3+
.SYNOPSIS
4+
Format the name of a Pester object for display.
5+
6+
.DESCRIPTION
7+
This function formats the name of a Pester object for display in a way that is compatible with Spectre.Console.
8+
It uses the object's name and result to determine the appropriate icon and color for display.
9+
It returns a string that can be used in Spectre.Console output.
10+
11+
.PARAMETER Object
12+
The Pester object to format. This should be a Pester Run or TestResult object.
13+
It is mandatory and can be piped in.
14+
15+
.PARAMETER NoColor
16+
A switch to disable color formatting in the output. If specified, the name will be returned without any color
17+
or icon.
18+
19+
.EXAMPLE
20+
$pesterResult.Containers[0].Blocks[0] | Format-PesterObjectName
21+
22+
This would format the name of the first block in the first container of a Pester result,
23+
returning a string with the appropriate icon and color based on the result of the test.
24+
#>
225
[CmdletBinding()]
326
[OutputType([string])]
427
param (

PesterExplorer/Private/Format-PesterTreeHash.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
11
function Format-PesterTreeHash {
2+
<#
3+
.SYNOPSIS
4+
Format a Pester object into a hashtable for tree display.
5+
6+
.DESCRIPTION
7+
This function takes a Pester object and formats it into a hashtable that can
8+
be used to display a tree structure in a TUI (Text User Interface). It
9+
handles different types of Pester objects such as Run, Container, Block, and
10+
Test, recursively building a tree structure with children nodes.
11+
12+
.PARAMETER Object
13+
The Pester object to format. This can be a Run, Container, Block, or Test
14+
object. The function will traverse the object and its children, formatting
15+
them into a hashtable structure.
16+
17+
.EXAMPLE
18+
$run = Invoke-Pester -Path 'tests' -PassThru
19+
$treeHash = Format-PesterTreeHash -Object $run
20+
21+
.NOTES
22+
This returns a hashtable with the following structure:
23+
@{
24+
Value = "Pester Run" # or the name of the object
25+
Children = @(
26+
@{
27+
Value = "Container Name"
28+
Children = @(
29+
@{
30+
Value = "Block Name"
31+
Children = @(
32+
@{
33+
Value = "Test Name"
34+
Children = @()
35+
}
36+
)
37+
}
38+
)
39+
}
40+
)
41+
}
42+
#>
243
[CmdletBinding()]
344
[OutputType([hashtable])]
445
param (

PesterExplorer/Private/Get-LastKeyPressed.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
11
function Get-LastKeyPressed {
2+
<#
3+
.SYNOPSIS
4+
Get the last key pressed in the console.
5+
6+
.DESCRIPTION
7+
This function checks if any key has been pressed in the console and returns
8+
the last key pressed. It is useful for handling user input in a TUI (Text
9+
User Interface) environment.
10+
11+
.EXAMPLE
12+
$key = Get-LastKeyPressed
13+
if ($key -eq "Enter") {
14+
# Make the TUI do something
15+
}
16+
17+
This example retrieves the last key pressed and checks if it was the Enter
18+
key.
19+
20+
.NOTES
21+
This function is meant to be used in a TUI context where you need to
22+
handle user input. It reads the console key buffer and returns the last key
23+
pressed without displaying it on the console.
24+
#>
25+
[CmdletBinding()]
26+
[OutputType([ConsoleKeyInfo])]
27+
param ()
228
$lastKeyPressed = $null
329
while ([Console]::KeyAvailable) {
430
$lastKeyPressed = [Console]::ReadKey($true)

PesterExplorer/Private/Get-ListFromObject.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
function Get-ListFromObject {
2+
<#
3+
.SYNOPSIS
4+
Create a list from a Pester object for creating the items for the list.
5+
6+
.DESCRIPTION
7+
This function takes a Pester object (Run, Container, Block, or List) and
8+
formats it into an ordered dictionary that can be used to display a tree
9+
structure in a TUI (Text User Interface). It handles different types of
10+
Pester objects, extracting relevant information such as container names,
11+
block names, and test names. The function returns an ordered dictionary
12+
where the keys are formatted names and the values are the corresponding
13+
Pester objects.
14+
15+
.PARAMETER Object
16+
The Pester object to format. This can be a Run, Container, Block, or List
17+
object. The function will traverse the object and its children, formatting
18+
them into an ordered dictionary structure.
19+
20+
.EXAMPLE
21+
$run = Invoke-Pester -Path 'tests' -PassThru
22+
$list = Get-ListFromObject -Object $run
23+
24+
This example retrieves a Pester run object and formats it into an ordered
25+
dictionary for tree display.
26+
#>
227
[CmdletBinding()]
328
[OutputType([System.Collections.Specialized.OrderedDictionary])]
429
param (

PesterExplorer/Private/Get-ListPanel.ps1

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
function Get-ListPanel {
2+
<#
3+
.SYNOPSIS
4+
Create a list panel for displaying items in a TUI.
5+
6+
.DESCRIPTION
7+
This function generates a list panel that displays items in a TUI (Text User
8+
Interface) using Spectre.Console. It formats the items based on whether they
9+
are selected or not, and handles special cases like parent directories.
10+
11+
.PARAMETER List
12+
An array of strings to display in the list. Each item can be a file path,
13+
a test name, or a special item like '..' for parent directories.
14+
15+
.PARAMETER SelectedItem
16+
The item that is currently selected in the list. This will be highlighted
17+
differently from unselected items.
18+
19+
.EXAMPLE
20+
Get-ListPanel -List @('file1.txt', 'file2.txt', '..') -SelectedItem 'file1.txt'
21+
22+
This example creates a list panel with three items, highlighting 'file1.txt'
23+
as the selected item.
24+
.NOTES
25+
This is meant to be called by the main TUI function: Show-PesterResult
26+
#>
227
[CmdletBinding()]
328
param (
429
[array]
@@ -17,9 +42,11 @@ function Get-ListPanel {
1742
if($name -eq '..') {
1843
# This is a parent item, so we show it as a folder
1944
if ($name -eq $SelectedItem) {
20-
Write-SpectreHost ":up_arrow: [Turquoise2]$name[/]" -PassThru | Format-SpectrePadded -Padding 1
45+
Write-SpectreHost ":up_arrow: [Turquoise2]$name[/]" -PassThru |
46+
Format-SpectrePadded -Padding 1
2147
} else {
22-
Write-SpectreHost "$name" -PassThru | Format-SpectrePadded -Padding 0
48+
Write-SpectreHost "$name" -PassThru |
49+
Format-SpectrePadded -Padding 0
2350
}
2451
}
2552
elseif(Test-Path $name){
@@ -28,18 +55,32 @@ function Get-ListPanel {
2855
$name
2956
)
3057
if ($name -eq $SelectedItem) {
31-
Format-SpectreTextPath -Path $relativePath | Format-SpectrePadded -Padding 1
58+
Format-SpectreTextPath -Path $relativePath |
59+
Format-SpectrePadded -Padding 1
3260
} else {
33-
Format-SpectreTextPath -Path $relativePath -PathStyle $unselectedStyle | Format-SpectrePadded -Padding 0
61+
$formatSpectreTextPathSplat = @{
62+
Path = $relativePath
63+
PathStyle = $unselectedStyle
64+
}
65+
Format-SpectreTextPath @formatSpectreTextPathSplat |
66+
Format-SpectrePadded -Padding 0
3467
}
3568
}
3669
else {
3770
if ($name -eq $SelectedItem) {
38-
Write-SpectreHost ":right_arrow: [Turquoise2]$name[/]" -PassThru | Format-SpectrePadded -Padding 1
71+
$writeSpectreHostSplat = @{
72+
PassThru = $true
73+
Message = ":right_arrow: [Turquoise2]$name[/]"
74+
}
75+
Write-SpectreHost @writeSpectreHostSplat |
76+
Format-SpectrePadded -Padding 1
3977
} else {
40-
Write-SpectreHost $name -PassThru | Format-SpectrePadded -Padding 0
78+
Write-SpectreHost $name -PassThru |
79+
Format-SpectrePadded -Padding 0
4180
}
4281
}
4382
}
44-
$results | Format-SpectreRows | Format-SpectrePanel -Header "[white]List[/]" -Expand
83+
$results |
84+
Format-SpectreRows |
85+
Format-SpectrePanel -Header "[white]List[/]" -Expand
4586
}

0 commit comments

Comments
 (0)