Skip to content

Commit 8ef51f0

Browse files
🩹 [Patch]: Sort the return for Get-GitHubContext (#505)
## Description This pull request focuses on improving the usability and consistency of the GitHub context management PowerShell module. The main changes include renaming parameter sets and internal logic for clarity, ensuring output is sorted for better user experience, and updating the context completer for more accurate and user-friendly suggestions. - Fixes #503 **Parameter set and logic improvements:** * Renamed parameter sets in `Get-GitHubContext.ps1` for clarity (e.g., `'NamedContext'` to `'Get a named context'`, `'ListAvailableContexts'` to `'List all available contexts'`) and updated corresponding internal logic and debug messages for consistency. **Output and completion enhancements:** * Sorted the output of contexts by name in `Get-GitHubContext.ps1` to provide a more organized and predictable result. * Moved `completers.ps1` from the private to public directory, and updated the context completer to suppress debug output, sort and deduplicate context names, and improve the accuracy of completion suggestions. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 4d83c75 commit 8ef51f0

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/functions/public/Auth/Context/Get-GitHubContext.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
Justification = 'Encapsulated in a function. Never leaves as a plain text.'
2020
)]
2121
[OutputType([GitHubContext])]
22-
[CmdletBinding(DefaultParameterSetName = '__AllParameterSets')]
22+
[CmdletBinding(DefaultParameterSetName = 'Get default context')]
2323
param(
2424
# The name of the context.
2525
[Parameter(
2626
Mandatory,
27-
ParameterSetName = 'NamedContext'
27+
ParameterSetName = 'Get a named context'
2828
)]
2929
[Alias('Name')]
3030
[string] $Context,
3131

3232
# List all available contexts.
3333
[Parameter(
3434
Mandatory,
35-
ParameterSetName = 'ListAvailableContexts'
35+
ParameterSetName = 'List all available contexts'
3636
)]
3737
[switch] $ListAvailable
3838
)
@@ -45,11 +45,11 @@
4545

4646
process {
4747
switch ($PSCmdlet.ParameterSetName) {
48-
'NamedContext' {
49-
Write-Debug "NamedContext: [$Context]"
48+
'Get a named context' {
49+
Write-Debug "Get a named context: [$Context]"
5050
$ID = $Context
5151
}
52-
'ListAvailableContexts' {
52+
'List all available contexts' {
5353
Write-Debug "ListAvailable: [$ListAvailable]"
5454
$ID = '*'
5555
}
@@ -85,12 +85,11 @@
8585
throw "Unknown context type: [$($contextObj.Type)]"
8686
}
8787
}
88-
}
88+
} | Sort-Object -Property Name
8989
}
9090

9191
end {
9292
Write-Debug "[$stackPath] - End"
9393
}
9494
}
9595
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '8.1.3' }
96-

src/functions/private/Auth/Context/completers.ps1 renamed to src/functions/public/Auth/Context/completers.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
$contexts += 'Anonymous'
1313
}
1414

15-
$contexts += (Get-GitHubContext -ListAvailable -Verbose:$false).Name
15+
$contexts += (Get-GitHubContext -ListAvailable -Verbose:$false -Debug:$false).Name
16+
$contexts = $contexts | Sort-Object -Unique
1617
$contexts | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
1718
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
1819
}
File renamed without changes.

0 commit comments

Comments
 (0)