Refactor CLI to use System.CommandLine - #112
Conversation
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the Xping.Cli command-line surface from custom argument parsing to System.CommandLine, aligning CLI behavior and diagnostics with the library’s built-in parsing/validation model and updating tests accordingly.
Changes:
- Replaced manual verb/option parsing in
src/Xping.Cli/Program.cswith aRootCommand+ subcommands (report,where,clear,version) and System.CommandLine validators/parsers. - Updated CLI tests to assert on System.CommandLine’s standardized error/help text.
- Removed legacy option parsing types (
WhereOptions,ClearOptions) and convertedReportOptionsto a simple mutable options bag.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Xping.Cli.Tests/ProgramTests.cs | Updates expectations to match new help output and parse error wording. |
| tests/Xping.Cli.Tests/Commands/ReviewFixesTests.cs | Updates assertions for missing-argument / unrecognized-token errors produced by System.CommandLine. |
| tests/Xping.Cli.Tests/Commands/ReportCommandTests.cs | Updates assertions for unknown options and missing option values under the new parser. |
| src/Xping.Cli/Xping.Cli.csproj | Adds System.CommandLine package reference required for the refactor. |
| src/Xping.Cli/Program.cs | Implements the new command model, option definitions, validation, and invocation flow. |
| src/Xping.Cli/Commands/WhereOptions.cs | Deletes obsolete manual parsing type. |
| src/Xping.Cli/Commands/ReportOptions.cs | Removes parsing logic and makes properties settable for command binding. |
| src/Xping.Cli/Commands/ClearOptions.cs | Deletes obsolete manual parsing type. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…and help hint CustomParser now indexes into Tokens defensively instead of calling Single(), and parse-error hints point at the specific subcommand's --help again instead of always suggesting the root help. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Both now read AssemblyInformationalVersionAttribute directly, so the `version` subcommand no longer diverges from System.CommandLine's built-in --version option (previously 1.0.0.0 vs 1.0.0+<sha>).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Suppressed comments (3)
src/Xping.Cli/Program.cs:146
- Inside
SetAction, option values are read viaparseResult.GetValue(...), but in System.CommandLine 2.0 the supported API isGetValueForOption(...). UsingGetValuehere will fail to compile against the referenced package.
var options = new ReportOptions
{
Last = parseResult.GetValue(lastOption),
Assembly = parseResult.GetValue(assemblyOption),
Directory = parseResult.GetValue(directoryOption),
src/Xping.Cli/Program.cs:203
clearcommand handler reads option values viaparseResult.GetValue(...), but System.CommandLine 2.0 usesGetValueForOption(...). As written this will not compile against the referenced package version.
command.SetAction(parseResult => ClearCommand.Run(
parseResult.GetValue(directoryOption),
parseResult.GetValue(assemblyOption),
parseResult.GetValue(forceOption),
input,
src/Xping.Cli/Program.cs:169
wherecommand handler reads the option value viaparseResult.GetValue(...), but System.CommandLine 2.0 usesGetValueForOption(...). This should be updated to match the referenced API.
Command command = new("where", "Show where local runs are stored") { directoryOption };
command.SetAction(parseResult => WhereCommand.Run(parseResult.GetValue(directoryOption), output));
Migrate the command-line interface to utilize System.CommandLine for improved command handling and option parsing. Update error messages for consistency and clarity. Remove outdated option parsing classes.