Migrate System.CommandLine 2.0-beta4 to 3.0-preview - #8
Merged
Conversation
Bumps System.CommandLine from 2.0.0-beta4.22272.1 to 3.0.0-preview.7.26381.103, which unblocks the daily automated "Update Packages" workflow that has been failing to apply this exact bump (dotnet build failed with ~24 CS errors after the version bump alone). Ports Source/Generator/Program.cs to the reworked 3.0-preview API: - Option<T> construction no longer takes a description: named parameter; Description is now a settable property inherited from Symbol, and IsRequired is renamed to Required. - getDefaultValue: is replaced by the DefaultValueFactory property (Func<ArgumentResult, T>). - RootCommand.AddOption is replaced by the Options.Add(...) collection property. - Command.SetHandler is replaced by Command.SetAction(...), which receives a ParseResult (and CancellationToken for the async overload) instead of bound option values; values are now read via parseResult.GetValue(option). - RootCommand.InvokeAsync(args) is replaced by parsing first (rootCommand.Parse(args)) and then invoking the resulting ParseResult (parseResult.InvokeAsync()). Verified with dotnet build (clean, no errors) and manual smoke tests of the built protocol-generator tool: --help output, missing required option handling, and a full generation run all match prior behavior. No test/spec project exists in this repo to run. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Merged
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The daily automated Update Packages workflow has been failing every day trying to bump
System.CommandLinefrom2.0.0-beta4.22272.1to the3.0.0-previewline inDirectory.Packages.props. That's a breaking API rewrite between the 2.x beta line and the 3.x preview line, so the bump alone (with no code changes) failsdotnet buildwith ~24 compiler errors inSource/Generator/Program.cs(CS1739,CS0117,CS1061, ...). Because the workflow only commits on a successful build, nothing was ever pushed tomain—mainhas stayed safely on2.0.0-beta4while the workflow silently failed day after day.This PR does the migration deliberately:
System.CommandLineinDirectory.Packages.propsto3.0.0-preview.7.26381.103(the latest3.0.0-previewbuild currently on NuGet.org, confirmed viadotnet package search System.CommandLine --prerelease).Source/Generator/Program.cs(the only consumer of the API, shared intoSource/Generator.Buildvia a source-file glob include) to the reworked 3.0-preview surface, preserving the exact same CLI options/behavior:Option<T>construction no longer accepts adescription:named parameter.Descriptionis now a plain settable property (inherited from theSymbolbase class), andIsRequiredwas renamed toRequired.getDefaultValue:is replaced by theDefaultValueFactoryproperty (Func<ArgumentResult, T>).RootCommand.AddOption(...)is replaced by theOptions.Add(...)collection property.Command.SetHandler(...)is replaced byCommand.SetAction(...), which hands the action aParseResult(+CancellationTokenfor the async overload) instead of pre-bound option values — values are now pulled out explicitly viaparseResult.GetValue(option).RootCommand.InvokeAsync(args)is replaced by a two-steprootCommand.Parse(args)→parseResult.InvokeAsync().The exact API shape was confirmed by decompiling the installed
3.0.0-preview.7.26381.103package (viailspycmd) rather than guessing from memory, since the 3.0-preview surface has moved across preview builds.Test plan
dotnet buildat the repo root succeeds with zero errors (previously ~24CS****errors acrossGenerator.csprojandGenerator.Build.csproj).protocol-generatortool:--helpoutput shows the same options, required flags, defaults, and descriptions as before.HandleCommandcatch block, printingError: Assembly not found: ...and exiting 1 (same as before).Backend.dll) with default--base-namespace/--skip-segmentssuccessfully generates the expected service interfaces and DTOs.🤖 Generated with Claude Code