Skip to content

Conversation

AdmiringWorm
Copy link
Member

Description Of Changes

Enhances PowerShell tab completion for Chocolatey install and upgrade commands by dynamically listing available --version values for a specified package. Specifically:

  • Adds a new chocoRemotePackageVersions helper function to query all available versions for a given package via choco search.
  • Updates ChocolateyTabExpansion to detect version requests and emit completions using a match on partial version input.
  • Improves Pester coverage by adding various test cases that validate behavior for:
    • Empty, quoted, and partially typed --version values.
    • Filtering of results based on major version input (e.g., 2 returns only 2.x).

Motivation and Context

Users installing or upgrading packages via Chocolatey sometimes need to specify a version manually. Without completions, this requires knowing exact version strings in advance. This change improves usability by providing context-aware completions for the --version parameter based on available versions from the remote source. It also adds comprehensive tests to verify correctness and edge case behavior.

Testing

  1. Manually tested interactive tab completion for choco install and choco upgrade using various --version inputs. (--version=, --version=' and --version=''. Latest need to have the cursor between the single quotes).
  2. Added Pester tests to verify (Not yet run):
    • Completions return the correct version set.
    • Filtering is applied based on user-typed prefix.
    • Behavior differs when the cursor is placed before vs. after closing quotes.

Operating Systems Testing

  • Windows 11

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed? (Not run yet, will run as part of this PR)
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

@AdmiringWorm AdmiringWorm requested a review from gep13 June 30, 2025 11:11
@AdmiringWorm AdmiringWorm self-assigned this Jun 30, 2025
@AdmiringWorm AdmiringWorm force-pushed the PROJ-1501_PowerShell-tab-completion-option-filter-improvements_Kim-Nordmo branch 2 times, most recently from d9257e3 to 2c55b69 Compare June 30, 2025 13:48
@AdmiringWorm AdmiringWorm force-pushed the PROJ-1501_PowerShell-tab-completion-option-filter-improvements_Kim-Nordmo branch 2 times, most recently from 92e322e to 6817ac3 Compare July 1, 2025 08:19
@gep13
Copy link
Member

gep13 commented Jul 1, 2025

@AdmiringWorm is this still in draft, or is this ready for review?

@AdmiringWorm
Copy link
Member Author

@AdmiringWorm is this still in draft, or is this ready for review?

It is still in draft, waiting on the test kitchen to finish.
Once it have finished and succeed I will get this PR rebased and open it up for review.

@AdmiringWorm AdmiringWorm force-pushed the PROJ-1501_PowerShell-tab-completion-option-filter-improvements_Kim-Nordmo branch from d65d88f to a7c35a4 Compare July 1, 2025 10:31
@AdmiringWorm AdmiringWorm marked this pull request as ready for review July 1, 2025 10:32
@AdmiringWorm
Copy link
Member Author

@gep13 I have opened this for review now, it succeeded internally on the 2016 image, but failed to spin up the 2019 image (but since it succeeded on one of them, I think it is fine).

Add chocoRemotePackageVersions function to fetch package versions from
remote source and integrate it into tab completion for install and upgrade
commands with --version option. This enables listing of available versions
for a specified package, improving user experience when specifying versions.

Add Pester tests to verify version completions appear correctly for various
--version input scenarios and cursor positions, ensuring reliable behavior.
Modify GetSortOrder to accept an outputWarnings parameter that controls
whether client-side ordering warnings are logged. This prevents unwanted
warnings when output is suppressed, improving user experience during
quiet or non-regular output scenarios. Update all callers accordingly.
@gep13 gep13 force-pushed the PROJ-1501_PowerShell-tab-completion-option-filter-improvements_Kim-Nordmo branch from a7c35a4 to d8f44f0 Compare July 1, 2025 11:05
@gep13 gep13 enabled auto-merge July 1, 2025 11:05
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gep13 gep13 merged commit 0e6f7e7 into chocolatey:develop Jul 1, 2025
5 checks passed
@gep13
Copy link
Member

gep13 commented Jul 1, 2025

@AdmiringWorm this looks great! Thank you for taking the time to get this added! This will be a big help going forward!

@AdmiringWorm AdmiringWorm deleted the PROJ-1501_PowerShell-tab-completion-option-filter-improvements_Kim-Nordmo branch July 1, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expand the ChocolateyTabExpansion.ps1 file with completions for multiple Chocolatey CLI commands
3 participants