-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate CLI bootstrap to System.CommandLine 2.0.3 APIs #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,29 +15,32 @@ | |||||
| RootCommand rootCommand = new("MUD Proxy"); | ||||||
|
|
||||||
| 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 }; | ||||||
| hostNameOption.Aliases.Add("-h"); | ||||||
| rootCommand.Add(hostNameOption); | ||||||
|
|
||||||
| Option<int> hostPortOption = | ||||||
| new("--host-port", "Port to connect to the MUD server on.") { IsRequired = true }; | ||||||
| hostPortOption.AddAlias("-p"); | ||||||
| new("--host-port") { Description = "Port to connect to the MUD server on.", Required = true }; | ||||||
| hostPortOption.Aliases.Add("-p"); | ||||||
| rootCommand.Add(hostPortOption); | ||||||
|
|
||||||
| Option<int> proxyPortOption = | ||||||
| new("--proxy-port", "Port the MUD proxy will listen for clients on.") { IsRequired = true }; | ||||||
| proxyPortOption.AddAlias("-l"); | ||||||
| new("--proxy-port") { Description = "Port the MUD proxy will listen for clients on.", Required = true }; | ||||||
| proxyPortOption.Aliases.Add("-l"); | ||||||
| rootCommand.Add(proxyPortOption); | ||||||
|
|
||||||
| Option<bool> mccp2Option = | ||||||
| new("--mccp", "Enable MUD Client Compression V2 (MCCP2) if the server supports it."); | ||||||
| mccp2Option.AddAlias("-c"); | ||||||
| new("--mccp") { Description = "Enable MUD Client Compression V2 (MCCP2) if the server supports it." }; | ||||||
| mccp2Option.Aliases.Add("-c"); | ||||||
| rootCommand.Add(mccp2Option); | ||||||
|
|
||||||
| rootCommand.SetHandler(async ( | ||||||
| string hostName, int hostPort, int proxyPort, bool enableMccp2 | ||||||
| ) => | ||||||
| rootCommand.SetAction(async parseResult => | ||||||
| { | ||||||
| string hostName = parseResult.GetValue(hostNameOption)!; | ||||||
| int hostPort = parseResult.GetValue(hostPortOption); | ||||||
| int proxyPort = parseResult.GetValue(proxyPortOption); | ||||||
| bool enableMccp2 = parseResult.GetValue(mccp2Option); | ||||||
|
|
||||||
| Proxy proxy = new(enableMccp2); | ||||||
|
|
||||||
| Task clientTask = proxy.ListenForClientsAsync(proxyPort, cancelToken); | ||||||
|
|
@@ -54,8 +57,8 @@ | |||||
| await Task.WhenAll(clientTask, hostTask); | ||||||
|
|
||||||
| Console.WriteLine("Program exiting."); | ||||||
| }, hostNameOption, hostPortOption, proxyPortOption, mccp2Option); | ||||||
| }); | ||||||
|
Comment on lines
37
to
+60
|
||||||
|
|
||||||
| await rootCommand.InvokeAsync(args); | ||||||
| await rootCommand.Parse(args).InvokeAsync(); | ||||||
|
||||||
| await rootCommand.Parse(args).InvokeAsync(); | |
| await rootCommand.InvokeAsync(args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = trueas the property name, notRequired = true.This issue also appears in the following locations of the same file:
See below for a potential fix: