Skip to content

Conversation

@baronfel
Copy link
Member

@baronfel baronfel commented Sep 8, 2025

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.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2025

This PR is targeting main, which is now for .NET 11-facing work. If you intended to target .NET 10, either retarget this PR to release/10.0.1xx or make sure you backport the change to release/10.0.1xx after merging. See #50394 for more details.

Copy link
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 refactors the command-line option and argument infrastructure by:

  • Extracting command-line extensions into a new Microsoft.DotNet.Cli.CommandLine project 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 standard Option<T> types
  • Consolidating documentation link handling through extension properties instead of the ICommandDocument interface
  • 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

@baronfel
Copy link
Member Author

This is green at last @MiYanni!

@baronfel baronfel merged commit e76657c into dotnet:main Nov 5, 2025
27 checks passed
@baronfel baronfel deleted the more-scl-patterns branch November 5, 2025 14:24
@baronfel
Copy link
Member Author

baronfel commented Nov 7, 2025

/backport to release/10.0.2xx

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Started backporting to release/10.0.2xx (link to workflow run)

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

@baronfel backporting to release/10.0.2xx failed, the patch most likely resulted in conflicts. Please backport manually!

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

Link to workflow output

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants