Repository navigation
Fix invalid argument handling for workload search version - #55682
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: c380ce6f-a051-44c6-810f-46d8c8d6b747
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR fixes argument validation for dotnet workload search version so the command reliably supports its three intended modes while ensuring invalid inputs fail via standard CLI parsing (rather than throwing InvalidOperationException). It also adds a regression test to assert the localized “unrecognized argument” message for mistyped option-like inputs captured by the variadic positional argument.
Changes:
- Adjust
workload search versionvalidation to correctly distinguish: no args (list),package@versionargs (match sets), and a single workload-set version (inspect set). - Prevent invalid combinations (mixed or multiple non-component args) from reaching execution paths that can throw due to
.Single()/SingleOrDefault()misuse. - Add test coverage asserting the localized unrecognized-argument message for inputs like
-foo bar.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Workload/Search/GivenDotnetWorkloadSearch.cs | Extends regression coverage to include option-like typos and asserts the localized unrecognized-argument message. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Workload/WorkloadSearchVersionsCommandDefinition.cs | Updates validator logic to safely handle multiple/invalid arguments without throwing and to preserve the three supported invocation modes. |
Co-authored-by: Copilot App <[email protected]> Copilot-Session: c380ce6f-a051-44c6-810f-46d8c8d6b747
|
Tested in codespace and confirmed I could still do search version actions but if I did invalid commands, it worked. It was showing the whole help on error and I asked it to fix that. Confirmed that an error no longer spits out the full help and help still works. |
baronfel
left a comment
There was a problem hiding this comment.
The core fix looks good, but the top-level showhelp wrapper is gross as heck. I'll approve once your agent is done removing that :D
Keep help-output changes out of this targeted argument-validation fix. Co-authored-by: Copilot App <[email protected]> Copilot-Session: c380ce6f-a051-44c6-810f-46d8c8d6b747
Summary
dotnet workload search versionmodes:package@versionarguments to find matching workload setsInvalidOperationException-foo barand assert the localized unrecognized-argument messageThis is intentionally compatible with #55681, which adds NuGet options to the same command. Recognized options continue to parse as options, while typos captured by the variadic positional argument now fail cleanly.
Help-output behavior is intentionally unchanged and will be addressed separately.
Validation
build.cmdGivenInvalidArgumentToWorkloadSearchVersionItFailsCleanly(6 cases)Unrecognized command or argument '-foo bar'with exit code 1