Skip to content

Show help output when there are unmatched tokens passed to update-dependencies CLI#6402

Merged
lbussell merged 2 commits into
dotnet:nightlyfrom
lbussell:issue-6394
Apr 30, 2025
Merged

Show help output when there are unmatched tokens passed to update-dependencies CLI#6402
lbussell merged 2 commits into
dotnet:nightlyfrom
lbussell:issue-6394

Conversation

@lbussell
Copy link
Copy Markdown
Member

Fixes #6394

System.Commandline.Hosting forcibly sets yourCommand.TreatUnmatchedTokensAsErrors = false and also overrides the command's action, so we can't fix this behavior by either of those means.

However, unmatched tokens are passed to the hostBuilderFactory, which allows you to configure additional hosting options based on those extra tokens. Since we don't need those extra arguments, we can use that opportunity to print the help output and throw an exception.

https://github.com/dotnet/command-line-api/blob/a91bcf488ba7d0112b2637b505f8de32aded6825/src/System.CommandLine.Hosting/HostingAction.cs#L26-L27

@lbussell lbussell requested a review from a team as a code owner April 29, 2025 16:43
Comment thread eng/update-dependencies/Program.cs Outdated
@lbussell lbussell requested a review from Copilot April 29, 2025 18:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the update-dependencies CLI to show the help output when unmatched tokens are provided, and then throws an exception containing the extra tokens.

  • Introduces a hostBuilderFactory lambda to check for unmatched tokens.
  • Uses HelpBuilder to display the help message before throwing an InvalidOperationException.

Co-authored-by: Matt Thalman <mthalman@microsoft.com>
@lbussell lbussell merged commit 1cffd0e into dotnet:nightly Apr 30, 2025
111 checks passed
lbussell added a commit to lbussell/dotnet-docker that referenced this pull request May 9, 2025
…endencies CLI (dotnet#6402)

Co-authored-by: Matt Thalman <mthalman@microsoft.com>
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.

3 participants