Migrate CLI bootstrap to System.CommandLine 2.0.3 APIs#75
Conversation
Co-authored-by: DanRigby <114417+DanRigby@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR attempts to migrate the CLI bootstrap code from System.CommandLine beta APIs to the stable 2.0.3 release, following the package upgrade in PR #74. However, the migration uses incorrect API methods that don't exist in System.CommandLine 2.0.3, which will prevent the code from compiling.
Changes:
- Updated
MudProxy.csprojto reference System.CommandLine version 2.0.3 (from beta version) - Attempted migration of CLI option definitions and command handler setup in
Program.cs, but used incorrect API names
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| MudProxy/MudProxy.csproj | Updated System.CommandLine package reference from 2.0.0-beta4.22272.1 to 2.0.3 |
| MudProxy/Program.cs | Attempted API migration that uses incorrect method names (SetAction, Required) and invocation pattern not present in System.CommandLine 2.0.3 |
Comments suppressed due to low confidence (2)
MudProxy/Program.cs:23
- The property name should be
IsRequiredin System.CommandLine 2.0.3, notRequired.
While the migration from the beta API's constructor parameter to a property is correct, the stable 2.0.3 API uses IsRequired = true as the property name, not Required = true.
new("--host-port") { Description = "Port to connect to the MUD server on.", Required = true };
MudProxy/Program.cs:28
- The property name should be
IsRequiredin System.CommandLine 2.0.3, notRequired.
While the migration from the beta API's constructor parameter to a property is correct, the stable 2.0.3 API uses IsRequired = true as the property name, not Required = true.
new("--proxy-port") { Description = "Port the MUD proxy will listen for clients on.", Required = true };
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -54,8 +57,8 @@ | |||
| await Task.WhenAll(clientTask, hostTask); | |||
|
|
|||
| Console.WriteLine("Program exiting."); | |||
| }, hostNameOption, hostPortOption, proxyPortOption, mccp2Option); | |||
| }); | |||
There was a problem hiding this comment.
The method SetAction does not exist in System.CommandLine 2.0.3. The stable 2.0.x API uses SetHandler instead.
In System.CommandLine 2.0.3, you should use SetHandler with a delegate that receives parameters, like:
rootCommand.SetHandler(async (string hostName, int hostPort, int proxyPort, bool enableMccp2) =>
{
// handler code
}, hostNameOption, hostPortOption, proxyPortOption, mccp2Option);
Alternatively, if you prefer the ParseResult approach, use:
rootCommand.SetHandler(async (ParseResult parseResult) =>
{
string hostName = parseResult.GetValue(hostNameOption)!;
// ...
});
The current code using SetAction will not compile with System.CommandLine 2.0.3.
| }); | ||
|
|
||
| await rootCommand.InvokeAsync(args); | ||
| await rootCommand.Parse(args).InvokeAsync(); |
There was a problem hiding this comment.
In System.CommandLine 2.0.3, the invocation pattern should be await rootCommand.InvokeAsync(args), not await rootCommand.Parse(args).InvokeAsync().
The Parse(args).InvokeAsync() pattern was from earlier beta versions. The stable 2.0.3 release uses the simpler InvokeAsync(args) method directly on the command.
| await rootCommand.Parse(args).InvokeAsync(); | |
| await rootCommand.InvokeAsync(args); |
| Option<string> hostNameOption = | ||
| new("--hostname", "Hostname of the MUD server to connect to.") { IsRequired = true }; | ||
| hostNameOption.AddAlias("-h"); | ||
| new("--hostname") { Description = "Hostname of the MUD server to connect to.", Required = true }; |
There was a problem hiding this comment.
The property name should be IsRequired in System.CommandLine 2.0.3, not Required.
While the migration from the beta API's constructor parameter to a property is correct, the stable 2.0.3 API uses IsRequired = true as the property name, not Required = true.
This issue also appears in the following locations of the same file:
- line 23
- line 28
See below for a potential fix:
new("--hostname") { Description = "Hostname of the MUD server to connect to.", IsRequired = true };
hostNameOption.Aliases.Add("-h");
rootCommand.Add(hostNameOption);
Option<int> hostPortOption =
new("--host-port") { Description = "Port to connect to the MUD server on.", IsRequired = true };
hostPortOption.Aliases.Add("-p");
rootCommand.Add(hostPortOption);
Option<int> proxyPortOption =
new("--proxy-port") { Description = "Port the MUD proxy will listen for clients on.", IsRequired = true };
PR #74 upgraded
System.CommandLineto2.0.3, but the app entrypoint still used pre-release APIs removed/renamed in stable releases, which broke build/CI. This updates the CLI wiring inProgram.csto the 2.0.3 surface with minimal behavioral change.CLI option API migration
IsRequiredwithRequired.AddAlias(...)withAliases.Add(...).Descriptioninstead of old constructor usage.Command handler/invocation migration
SetHandler(...)withSetAction(...).ParseResult.RootCommand.InvokeAsync(args)withrootCommand.Parse(args).InvokeAsync().Dependency alignment
MudProxy.csprojto useSystem.CommandLine2.0.3so source and package API expectations are consistent.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
www.jetbrains.com/usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.3.2/tools/net8.0/any/inspectcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.3.2/tools/net8.0/any/inspectcode.exe --no-build --swea --severity=SUGGESTION --format=xml --output=inspectcode.xml MudProxy.sln(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.