Skip to content

Sort Get-GitHubContext -ListAvailable output and unify sorted Context argument completers #503

@MariusStorhaug

Description

@MariusStorhaug

Summary
The output of Get-GitHubContext -ListAvailable is currently unsorted (appears insertion order). Need deterministic alphabetical ordering by Name while still preserving the current-indicator (">"), selected marker("*" header already present). Also ensure every parameter that accepts -Context (or similar) has its ArgumentCompleter returning contexts sorted by Name.

Requirements

  1. Get-GitHubContext -ListAvailable must sort contexts by Name (case-insensitive, ordinal) before formatting.
  2. Preserve the visual indicators (leading '>' on active context row) after sorting.
  3. Ensure expired / time remaining columns still show correctly.
  4. All ArgumentCompleter scripts for -Context (and related params like -SourceContext, -TargetContext if present) must return names sorted by Name.
  5. Centralize / relocate all completer definitions into a completers.ps1 file placed in each main function folder where completers are defined (one file per functional area). If a shared/global context completer exists, create (or update) functions/public/Config/completers.ps1 (or appropriate folder matching Get-GitHubContext location) and move definitions there.
  6. Avoid breaking existing exports: dot-source completers.ps1 from loader/header or the specific function file so they load automatically.
  7. Add or update tests to assert sorting for: a) Get-GitHubContext -ListAvailable output order, b) tab completion order for -Context parameters (collect via (Get-Command ).Parameters['Context'].Attributes where applicable or simulate Register-ArgumentCompleter result).

Implementation Notes

  • Likely modify the private retrieval function that enumerates contexts before formatting pipeline.
  • After selecting active context, perform: $items = $items | Sort-Object -Property Name -CultureInvariant -CaseInsensitive
  • Re-apply active marker based on matching name.
  • For completers, implement a helper Get-GitHubContextNameList (private) that returns sorted names; completers just call it.
  • Ensure no circular dot-sourcing.

Testing

  • Create temp contexts (mock) to validate ordering.
  • Ensure no regression in existing tests.

Next Steps

  • Implement sorting + helper.
  • Refactor completers into dedicated files.
  • Add/adjust tests.

Acceptance Criteria
All tests green; manual run shows alphabetical order exactly as specified in example.

Example Desired Output Order

github.com/MariusStorhaug
github.com/powershell-for-github
github.com/powershell-for-github/Organization/PSModule
github.com/psmodule-enterprise-app
github.com/psmodule-enterprise-app/Organization/psmodule-test-org3
github.com/psmodule-org-app

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions