Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AdmiringWorm
Copy link
Member

Description Of Changes

Adds validation to detect and reject attempts to pass a value to the -v (verbose) short option, which does not support values. If such usage is detected (e.g., -v:5.2.1 or /v='5.2.1'), the parser throws a helpful exception suggesting the user may have meant --version instead.

Also adds a corresponding test using [Fact, Combinatorial] to ensure the exception is thrown correctly across combinations of separators, quotes, and prefixes.

Motivation and Context

Users commonly mistake the -v (verbose) option for --version, leading to confusing or incorrect behavior when supplying a value. This change preempts the error by detecting the misuse early in argument parsing and providing a targeted suggestion to improve the user experience and prevent unintentional silent failures.

Testing

  1. Added a new Fact, Combinatorial test that validates the parser throws an ApplicationException for common invalid usages of -v with a value.
  2. Validated message formatting and suggestion output to guide users toward the correct --version usage.

Manual Tests:

  1. Run choco -v 5.2.1 and verify the expected excetpion message is outputted.
  2. Run choco search /v 2.1.6 and verify the expected exception message is outputted.
  3. Feel free to combine different seperators (=, : and , as well as with double and single quotes).

Operating Systems Testing

  • Windows 11

Change Types Made

  • Bug fix (non-breaking change) (Kinda breaking, but as it was never intended to work, we consider it non-breaking).
  • 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?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

@AdmiringWorm AdmiringWorm requested a review from gep13 June 30, 2025 15:52
@AdmiringWorm AdmiringWorm self-assigned this Jun 30, 2025
@AdmiringWorm AdmiringWorm force-pushed the prevent-value-for-verbose-option branch 2 times, most recently from 1929d7a to cff106f Compare July 1, 2025 08:32
Detect and throw an exception when a value is passed to the short
`-v` (verbose) option, which does not support explicit values. This
prevents user confusion and incorrect usage by suggesting the correct
`--version` option instead.

Add a test to verify that passing a value to `-v` triggers the expected
exception with a helpful message. This improves command line argument
parsing robustness and user experience.
@AdmiringWorm AdmiringWorm force-pushed the prevent-value-for-verbose-option branch from cff106f to 27f6e75 Compare July 1, 2025 10:34
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
Copy link
Member

gep13 commented Jul 1, 2025

The docker build is failing due to connection to NuGet.org.

Going to move forward with getting this merged.

@gep13 gep13 merged commit fc7fd5c into chocolatey:develop Jul 1, 2025
4 of 5 checks passed
@AdmiringWorm AdmiringWorm deleted the prevent-value-for-verbose-option 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.

Throw error (with suggestion on how to fix) when usage of -v option in conjunction with a version number is detected

2 participants