1717#endregion
1818
1919using System ;
20- using CommandLine ;
21- using Grpc . Core ;
22- using Grpc . Core . Logging ;
20+ using System . CommandLine ;
21+ using System . CommandLine . Invocation ;
22+ using System . Threading . Tasks ;
2323using Grpc . Shared . TestAssets ;
2424using Microsoft . Extensions . DependencyInjection ;
2525using Microsoft . Extensions . Logging ;
@@ -28,31 +28,43 @@ namespace InteropTestsClient
2828{
2929 public class Program
3030 {
31- public static void Main ( string [ ] args )
31+ public static async Task < int > Main ( string [ ] args )
3232 {
33- GrpcEnvironment . SetLogger ( new ConsoleLogger ( ) ) ;
34- var parserResult = Parser . Default . ParseArguments < ClientOptions > ( args )
35- . WithNotParsed ( errors => Environment . Exit ( 1 ) )
36- . WithParsed ( options =>
33+ var rootCommand = new RootCommand ( ) ;
34+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--client_type" , nameof ( ClientOptions . ClientType ) } , ( ) => "httpclient" ) ) ;
35+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--server_host" , nameof ( ClientOptions . ServerHost ) } ) { Required = true } ) ;
36+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--server_host_override" , nameof ( ClientOptions . ServerHostOverride ) } ) ) ;
37+ rootCommand . AddOption ( new Option < int > ( new string [ ] { "--server_port" , nameof ( ClientOptions . ServerPort ) } ) { Required = true } ) ;
38+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--test_case" , nameof ( ClientOptions . TestCase ) } ) { Required = true } ) ;
39+ rootCommand . AddOption ( new Option < bool > ( new string [ ] { "--use_tls" , nameof ( ClientOptions . UseTls ) } ) ) ;
40+ rootCommand . AddOption ( new Option < bool > ( new string [ ] { "--use_test_ca" , nameof ( ClientOptions . UseTestCa ) } ) ) ;
41+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--default_service_account" , nameof ( ClientOptions . DefaultServiceAccount ) } ) ) ;
42+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--oauth_scope" , nameof ( ClientOptions . OAuthScope ) } ) ) ;
43+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--service_account_key_file" , nameof ( ClientOptions . ServiceAccountKeyFile ) } ) ) ;
44+ rootCommand . AddOption ( new Option < string > ( new string [ ] { "--grpc_web_mode" , nameof ( ClientOptions . GrpcWebMode ) } ) ) ;
45+
46+ rootCommand . Handler = CommandHandler . Create < ClientOptions > ( async ( options ) =>
47+ {
48+ Console . WriteLine ( "Use TLS: " + options . UseTls ) ;
49+ Console . WriteLine ( "Use Test CA: " + options . UseTestCa ) ;
50+ Console . WriteLine ( "Client type: " + options . ClientType ) ;
51+ Console . WriteLine ( "Server host: " + options . ServerHost ) ;
52+ Console . WriteLine ( "Server port: " + options . ServerPort ) ;
53+
54+ var services = new ServiceCollection ( ) ;
55+ services . AddLogging ( configure =>
3756 {
38- Console . WriteLine ( "Use TLS: " + options . UseTls ) ;
39- Console . WriteLine ( "Use Test CA: " + options . UseTestCa ) ;
40- Console . WriteLine ( "Client type: " + options . ClientType ) ;
41- Console . WriteLine ( "Server host: " + options . ServerHost ) ;
42- Console . WriteLine ( "Server port: " + options . ServerPort ) ;
43-
44- var services = new ServiceCollection ( ) ;
45- services . AddLogging ( configure =>
46- {
47- configure . SetMinimumLevel ( Microsoft . Extensions . Logging . LogLevel . Trace ) ;
48- configure . AddConsole ( loggerOptions => loggerOptions . IncludeScopes = true ) ;
49- } ) ;
50-
51- using var serviceProvider = services . BuildServiceProvider ( ) ;
52-
53- var interopClient = new InteropClient ( options , serviceProvider . GetRequiredService < ILoggerFactory > ( ) ) ;
54- interopClient . Run ( ) . Wait ( ) ;
57+ configure . SetMinimumLevel ( LogLevel . Trace ) ;
58+ configure . AddConsole ( loggerOptions => loggerOptions . IncludeScopes = true ) ;
5559 } ) ;
60+
61+ using var serviceProvider = services . BuildServiceProvider ( ) ;
62+
63+ var interopClient = new InteropClient ( options , serviceProvider . GetRequiredService < ILoggerFactory > ( ) ) ;
64+ await interopClient . Run ( ) ;
65+ } ) ;
66+
67+ return await rootCommand . InvokeAsync ( args ) ;
5668 }
5769 }
5870}
0 commit comments