Skip to content

Refactor: Switch from CommandLineParser to System.CommandLine (#1016)#3014

Open
abdulrahmanhossam wants to merge 4 commits intodotnet:masterfrom
abdulrahmanhossam:feature/issue-1016-system-commandline
Open

Refactor: Switch from CommandLineParser to System.CommandLine (#1016)#3014
abdulrahmanhossam wants to merge 4 commits intodotnet:masterfrom
abdulrahmanhossam:feature/issue-1016-system-commandline

Conversation

@abdulrahmanhossam
Copy link

Description

This PR addresses issue #1016 by migrating the command-line argument parsing logic from the legacy CommandLineParser to the modern and stable System.CommandLine (v2.0).

Key Changes

  • Removed CommandLineParser and McMaster.Extensions.CommandLineUtils dependencies.
  • Added System.CommandLine package reference.
  • Refactored CommandLineOptions to define options using the new API.
  • Updated ConfigParser to handle the new parsing result and map it back to the options object.
  • Cleaned up old attributes and using directives.

Testing

  • Verified build success locally on Linux Mint.
  • Tested for all target frameworks (net6.0, net8.0, net9.0, net10.0, netstandard2.0).

Fixes #1016

@abdulrahmanhossam
Copy link
Author

@dotnet-policy-service agree

[Option('a', "artifacts", Required = false, HelpText = "Valid path to accessible directory")]
public DirectoryInfo? ArtifactsDirectory { get; set; }

[Option("outliers", Required = false, Default = OutlierMode.RemoveUpper, HelpText = "DontRemove/RemoveUpper/RemoveLower/RemoveAll")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Default = OutlierMode.RemoveUpper value also need to be migrated.
Currently it seems OutlierMode.DontRemove is used as default value.

@filzrev
Copy link
Contributor

filzrev commented Feb 19, 2026

When running BenchmarkDotNet.Tests unit tests.
50 tests failed on my Windows environment.

Therefore, I though it need to fix these tests first.

Other points of concern are listed below.

  1. Some existing argument names are change. (--disasm parameter --disassembly) and short name seems dropped.
  2. Help text is modified. It make harder to compare diffs.
  3. --help command option seems not be works. Because root command is used for commandline parsing and it's not invoked.

@abdulrahmanhossam
Copy link
Author

Thanks a lot for the detailed review and catching these points, @filzrev!

I have pushed a new commit that addresses all your concerns:

  1. Backward Compatibility: Restored all exact argument names, aliases (short names), and help texts to match the legacy CommandLineParser definitions to fix the 50 failing tests.
  2. Help Invocation: Fixed the --help (and -h, -?) behavior. It now correctly invokes the parser to print the help text.
  3. Default Values: Migrated the missing default values for Outliers (OutlierMode.RemoveUpper) and WasmArgs (--expose_wasm).

The local build is completely green now. Let me know if there is anything else needed!

DisassemblerFilters = parseResult.GetValue(CommandLineOptions.DisassemblerFiltersOption) ?? Array.Empty<string>(),
DisassemblerDiff = parseResult.GetValue(CommandLineOptions.DisassemblerDiffOption),
Outliers = parseResult.GetValue(CommandLineOptions.OutliersOption),
WasmArgs = parseResult.GetValue(CommandLineOptions.WasmJavaScriptEngineArgumentsOption),
Copy link
Contributor

@filzrev filzrev Feb 19, 2026

Choose a reason for hiding this comment

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

There are following two properties

  • WasmArgs (Option)
  • WasmJavaScriptEngineArguments (Plain Property)

I though WasmArgs option should be renamed to WasmJavaScriptEngineArguments.
And existing WasmJavaScriptEngineArguments plain property should be removed.

{ Description = "Sets the recursive depth for the disassembler. Default is 1.", DefaultValueFactory = _ => 1 };

public static readonly Option<OutlierMode> OutliersOption = new("--outliers")
{ Description = "Specifies outlier detection mode. Default is DontRemove.", DefaultValueFactory = _ => OutlierMode.DontRemove };
Copy link
Contributor

Choose a reason for hiding this comment

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

It need to set default value OutlierMode.RemoveUpper here to keep existing behavior.

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.

Switch from CommandLineParser and McMaster.Extensions.CommandLineUtils to System.CommandLine

3 participants

Comments