Make S.CL builder DSLs more transferable#50685
Merged
baronfel merged 11 commits intodotnet:mainfrom Nov 5, 2025
Merged
Conversation
Contributor
|
This PR is targeting |
1efb89e to
704e9a9
Compare
This was referenced Oct 28, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the command-line option and argument infrastructure by:
- Extracting command-line extensions into a new
Microsoft.DotNet.Cli.CommandLineproject to improve modularity and reusability - Replacing interface-based dynamic option/argument markers (
IDynamicOption,IDynamicArgument) with property-based extension methods (IsDynamic) - Replacing the
ForwardedOption<T>class hierarchy with extension methods on standardOption<T>types - Consolidating documentation link handling through extension properties instead of the
ICommandDocumentinterface - Removing specialized option classes (
DynamicOption,DynamicForwardedOption,DocumentedCommand) in favor of standard types with extensions
Reviewed Changes
Copilot reviewed 99 out of 99 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/Cli/Microsoft.DotNet.Cli.CommandLine/ (new project) |
New library containing reusable command-line extensions for forwarding, documentation, dynamic completions, and result navigation |
src/Cli/dotnet/CommonOptions.cs |
Updated to use standard Option<T> with extension methods instead of custom option classes |
src/Cli/dotnet/Extensions/OptionForwardingExtensions.cs |
Removed ForwardedOption<T> class and IForwardedOption interface, now handled by new project |
src/Cli/dotnet/Extensions/ParseResultExtensions.cs |
Moved utility methods to Microsoft.DotNet.Cli.CommandLine |
src/System.CommandLine.StaticCompletions/ |
Removed IDynamicOption and IDynamicArgument interfaces; replaced with IsDynamic property via extensions |
| Command parser files (multiple) | Updated to use standard Command with DocsLink extension instead of DocumentedCommand |
| Test files (multiple) | Updated using statements to reference new Microsoft.DotNet.Cli.CommandLine namespace |
src/Cli/Microsoft.DotNet.Cli.CommandLine/ForwardedOptionExtensions.cs
Outdated
Show resolved
Hide resolved
src/Cli/dotnet/Commands/Reference/Add/ReferenceAddCommandParser.cs
Outdated
Show resolved
Hide resolved
64978b7 to
824484f
Compare
This was referenced Oct 29, 2025
Member
Author
|
This is green at last @MiYanni! |
MiYanni
approved these changes
Nov 4, 2025
Member
Author
|
/backport to release/10.0.2xx |
Contributor
|
Started backporting to |
Contributor
|
@baronfel backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: add new project and move some base-layer stuff over
.git/rebase-apply/patch:111: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M sdk.slnx
M src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs
M src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs
M src/Cli/dotnet/Commands/Run/RunCommand.cs
M src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
M src/Cli/dotnet/Commands/Test/TestCommandParser.cs
M src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs
M src/Cli/dotnet/Commands/Tool/Install/ToolInstallGlobalOrToolPathCommand.cs
M src/Cli/dotnet/dotnet.csproj
Falling back to patching base and 3-way merge...
Auto-merging sdk.slnx
Auto-merging src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs
Auto-merging src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs
Auto-merging src/Cli/dotnet/Commands/Run/RunCommand.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/Commands/Test/TestCommandParser.cs
Auto-merging src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs
Auto-merging src/Cli/dotnet/Commands/Tool/Install/ToolInstallGlobalOrToolPathCommand.cs
Auto-merging src/Cli/dotnet/dotnet.csproj
Applying: Replace marker-interface dynamic completion with runtime-data-based variant.
Applying: forwarding is also just a set of extensions
Applying: Documentation links are now a separate feature as well, provided by extension members
error: sha1 information is lacking or useless (src/Cli/dotnet/Commands/Test/TestCommandParser.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0004 Documentation links are now a separate feature as well, provided by extension members
Error: The process '/usr/bin/git' failed with exit code 128 |
baronfel
added a commit
to baronfel/sdk
that referenced
this pull request
Nov 7, 2025
Co-authored-by: Marc Paine <marcpop@microsoft.com>
baronfel
added a commit
that referenced
this pull request
Nov 8, 2025
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.
This refactors all of our additional layers of functionality on top of System.CommandLine to be implemented in terms of C# 13 extension members. This has the major benefit of removing the inheritance-hierarchy hell/matrix of pain that we had already been struggling with as we create more feature-adds.
Each separate feature slice has been extracted into a separate 'slice' into a new CLI-extensibility project. The slices are
I also added a helper for making options and arguments for any type that supports
ISpanParsable<T>- we should move to this overall in the CLI to get us away from the reflection-based default parsing in System.CommandLine over time, and we should lean into this mechanism to support new user-defined types.Everything else is just adjusting to that core change.