@@ -62,66 +62,66 @@ class Program
6262
6363 public static async Task < int > Main ( string [ ] args )
6464 {
65- var urlOption = new Option < Uri > ( new string [ ] { "-u ", "--url" } , "The server url to request" ) { IsRequired = true } ;
66- var udsFileNameOption = new Option < string > ( new string [ ] { "--udsFileName" } , "The Unix Domain Socket file name" ) ;
67- var namedPipeNameOption = new Option < string > ( new string [ ] { "--namedPipeName" } , "The Named Pipe name" ) ;
68- var connectionsOption = new Option < int > ( new string [ ] { "-c ", "--connections" } , ( ) => 1 , "Total number of connections to keep open" ) ;
69- var warmupOption = new Option < int > ( new string [ ] { "-w ", "--warmup" } , ( ) => 5 , "Duration of the warmup in seconds" ) ;
70- var durationOption = new Option < int > ( new string [ ] { "-d ", "--duration" } , ( ) => 10 , "Duration of the test in seconds" ) ;
71- var callCountOption = new Option < int ? > ( new string [ ] { "--callCount" } , "Call count of test" ) ;
72- var scenarioOption = new Option < string > ( new string [ ] { "-s ", "--scenario" } , "Scenario to run" ) { IsRequired = true } ;
73- var latencyOption = new Option < bool > ( new string [ ] { "-l ", "--latency" } , ( ) => false , "Whether to collect detailed latency" ) ;
74- var protocolOption = new Option < string > ( new string [ ] { "-p ", "--protocol" } , "HTTP protocol" ) { IsRequired = true } ;
75- var logOption = new Option < LogLevel > ( new string [ ] { "-log ", "--logLevel" } , ( ) => LogLevel . None , "The log level to use for Console logging" ) ;
76- var requestSizeOption = new Option < int > ( new string [ ] { "--requestSize" } , "Request payload size" ) ;
77- var responseSizeOption = new Option < int > ( new string [ ] { "--responseSize" } , "Response payload size" ) ;
78- var grpcClientTypeOption = new Option < GrpcClientType > ( new string [ ] { "--grpcClientType" } , ( ) => GrpcClientType . GrpcNetClient , "Whether to use Grpc.NetClient or Grpc.Core client" ) ;
79- var streamsOption = new Option < int > ( new string [ ] { "--streams" } , ( ) => 1 , "Maximum concurrent streams per connection" ) ;
80- var enableCertAuthOption = new Option < bool > ( new string [ ] { "--enableCertAuth" } , ( ) => false , "Flag indicating whether client sends a client certificate" ) ;
81- var deadlineOption = new Option < int > ( new string [ ] { "--deadline" } , "Duration of deadline in seconds" ) ;
82- var winHttpHandlerOption = new Option < bool > ( new string [ ] { "--winhttphandler" } , ( ) => false , "Whether to use WinHttpHandler with Grpc.Net.Client" ) ;
65+ var urlOption = new Option < Uri > ( "--url ", [ "-u" ] ) { Description = "The server url to request" , Required = true } ;
66+ var udsFileNameOption = new Option < string > ( "--udsFileName" ) { Description = "The Unix Domain Socket file name" } ;
67+ var namedPipeNameOption = new Option < string > ( "--namedPipeName" ) { Description = "The Named Pipe name" } ;
68+ var connectionsOption = new Option < int > ( "--connections ", [ "-c" ] ) { DefaultValueFactory = ( r ) => 1 , Description = "Total number of connections to keep open" } ;
69+ var warmupOption = new Option < int > ( "--warmup ", [ "-w" ] ) { DefaultValueFactory = ( r ) => 5 , Description = "Duration of the warmup in seconds" } ;
70+ var durationOption = new Option < int > ( "--duration ", [ "-d" ] ) { DefaultValueFactory = ( r ) => 10 , Description = "Duration of the test in seconds" } ;
71+ var callCountOption = new Option < int ? > ( "--callCount" ) { Description = "Call count of test" } ;
72+ var scenarioOption = new Option < string > ( "--scenario ", [ "-s" ] ) { Description = "Scenario to run" , Required = true } ;
73+ var latencyOption = new Option < bool > ( "--latency ", [ "-l" ] ) { DefaultValueFactory = ( r ) => false , Description = "Whether to collect detailed latency" } ;
74+ var protocolOption = new Option < string > ( "--protocol ", [ "-p" ] ) { Description = "HTTP protocol" , Required = true } ;
75+ var logOption = new Option < LogLevel > ( "--logLevel ", [ "-log" ] ) { DefaultValueFactory = ( _ ) => LogLevel . None , Description = "The log level to use for Console logging" } ;
76+ var requestSizeOption = new Option < int > ( "--requestSize" ) { Description = "Request payload size" } ;
77+ var responseSizeOption = new Option < int > ( "--responseSize" ) { Description = "Response payload size" } ;
78+ var grpcClientTypeOption = new Option < GrpcClientType > ( "--grpcClientType" ) { DefaultValueFactory = ( r ) => GrpcClientType . GrpcNetClient , Description = "Whether to use Grpc.NetClient or Grpc.Core client" } ;
79+ var streamsOption = new Option < int > ( "--streams" ) { DefaultValueFactory = ( r ) => 1 , Description = "Maximum concurrent streams per connection" } ;
80+ var enableCertAuthOption = new Option < bool > ( "--enableCertAuth" ) { DefaultValueFactory = ( r ) => false , Description = "Flag indicating whether client sends a client certificate" } ;
81+ var deadlineOption = new Option < int > ( "--deadline" ) { Description = "Duration of deadline in seconds" } ;
82+ var winHttpHandlerOption = new Option < bool > ( "--winhttphandler" ) { DefaultValueFactory = ( r ) => false , Description = "Whether to use WinHttpHandler with Grpc.Net.Client" } ;
8383
8484 var rootCommand = new RootCommand ( ) ;
85- rootCommand . AddOption ( urlOption ) ;
86- rootCommand . AddOption ( udsFileNameOption ) ;
87- rootCommand . AddOption ( namedPipeNameOption ) ;
88- rootCommand . AddOption ( connectionsOption ) ;
89- rootCommand . AddOption ( warmupOption ) ;
90- rootCommand . AddOption ( durationOption ) ;
91- rootCommand . AddOption ( callCountOption ) ;
92- rootCommand . AddOption ( scenarioOption ) ;
93- rootCommand . AddOption ( latencyOption ) ;
94- rootCommand . AddOption ( protocolOption ) ;
95- rootCommand . AddOption ( logOption ) ;
96- rootCommand . AddOption ( requestSizeOption ) ;
97- rootCommand . AddOption ( responseSizeOption ) ;
98- rootCommand . AddOption ( grpcClientTypeOption ) ;
99- rootCommand . AddOption ( streamsOption ) ;
100- rootCommand . AddOption ( enableCertAuthOption ) ;
101- rootCommand . AddOption ( deadlineOption ) ;
102- rootCommand . AddOption ( winHttpHandlerOption ) ;
103-
104- rootCommand . SetHandler ( async ( InvocationContext context ) =>
85+ rootCommand . Add ( urlOption ) ;
86+ rootCommand . Add ( udsFileNameOption ) ;
87+ rootCommand . Add ( namedPipeNameOption ) ;
88+ rootCommand . Add ( connectionsOption ) ;
89+ rootCommand . Add ( warmupOption ) ;
90+ rootCommand . Add ( durationOption ) ;
91+ rootCommand . Add ( callCountOption ) ;
92+ rootCommand . Add ( scenarioOption ) ;
93+ rootCommand . Add ( latencyOption ) ;
94+ rootCommand . Add ( protocolOption ) ;
95+ rootCommand . Add ( logOption ) ;
96+ rootCommand . Add ( requestSizeOption ) ;
97+ rootCommand . Add ( responseSizeOption ) ;
98+ rootCommand . Add ( grpcClientTypeOption ) ;
99+ rootCommand . Add ( streamsOption ) ;
100+ rootCommand . Add ( enableCertAuthOption ) ;
101+ rootCommand . Add ( deadlineOption ) ;
102+ rootCommand . Add ( winHttpHandlerOption ) ;
103+
104+ rootCommand . SetAction ( async ( ParseResult context ) =>
105105 {
106106 _options = new ClientOptions ( ) ;
107- _options . Url = context . ParseResult . GetValueForOption ( urlOption ) ;
108- _options . UdsFileName = context . ParseResult . GetValueForOption ( udsFileNameOption ) ;
109- _options . NamedPipeName = context . ParseResult . GetValueForOption ( namedPipeNameOption ) ;
110- _options . Connections = context . ParseResult . GetValueForOption ( connectionsOption ) ;
111- _options . Warmup = context . ParseResult . GetValueForOption ( warmupOption ) ;
112- _options . Duration = context . ParseResult . GetValueForOption ( durationOption ) ;
113- _options . CallCount = context . ParseResult . GetValueForOption ( callCountOption ) ;
114- _options . Scenario = context . ParseResult . GetValueForOption ( scenarioOption ) ;
115- _options . Latency = context . ParseResult . GetValueForOption ( latencyOption ) ;
116- _options . Protocol = context . ParseResult . GetValueForOption ( protocolOption ) ;
117- _options . LogLevel = context . ParseResult . GetValueForOption ( logOption ) ;
118- _options . RequestSize = context . ParseResult . GetValueForOption ( requestSizeOption ) ;
119- _options . ResponseSize = context . ParseResult . GetValueForOption ( responseSizeOption ) ;
120- _options . GrpcClientType = context . ParseResult . GetValueForOption ( grpcClientTypeOption ) ;
121- _options . Streams = context . ParseResult . GetValueForOption ( streamsOption ) ;
122- _options . EnableCertAuth = context . ParseResult . GetValueForOption ( enableCertAuthOption ) ;
123- _options . Deadline = context . ParseResult . GetValueForOption ( deadlineOption ) ;
124- _options . WinHttpHandler = context . ParseResult . GetValueForOption ( winHttpHandlerOption ) ;
107+ _options . Url = context . GetValue ( urlOption ) ;
108+ _options . UdsFileName = context . GetValue ( udsFileNameOption ) ;
109+ _options . NamedPipeName = context . GetValue ( namedPipeNameOption ) ;
110+ _options . Connections = context . GetValue ( connectionsOption ) ;
111+ _options . Warmup = context . GetValue ( warmupOption ) ;
112+ _options . Duration = context . GetValue ( durationOption ) ;
113+ _options . CallCount = context . GetValue ( callCountOption ) ;
114+ _options . Scenario = context . GetValue ( scenarioOption ) ;
115+ _options . Latency = context . GetValue ( latencyOption ) ;
116+ _options . Protocol = context . GetValue ( protocolOption ) ;
117+ _options . LogLevel = context . GetValue ( logOption ) ;
118+ _options . RequestSize = context . GetValue ( requestSizeOption ) ;
119+ _options . ResponseSize = context . GetValue ( responseSizeOption ) ;
120+ _options . GrpcClientType = context . GetValue ( grpcClientTypeOption ) ;
121+ _options . Streams = context . GetValue ( streamsOption ) ;
122+ _options . EnableCertAuth = context . GetValue ( enableCertAuthOption ) ;
123+ _options . Deadline = context . GetValue ( deadlineOption ) ;
124+ _options . WinHttpHandler = context . GetValue ( winHttpHandlerOption ) ;
125125
126126 var runtimeVersion = typeof ( object ) . GetTypeInfo ( ) . Assembly . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ? . InformationalVersion ?? "Unknown" ;
127127 var isServerGC = GCSettings . IsServerGC ;
@@ -160,7 +160,8 @@ public static async Task<int> Main(string[] args)
160160
161161 Log ( "gRPC Client" ) ;
162162
163- return await rootCommand . InvokeAsync ( args ) ;
163+ var result = rootCommand . Parse ( args ) ;
164+ return await result . InvokeAsync ( ) ;
164165 }
165166
166167#if NET9_0_OR_GREATER
0 commit comments