@@ -11,11 +11,12 @@ sealed class DevProxyCommand : RootCommand
1111{
1212 private readonly IServiceProvider _serviceProvider ;
1313 private readonly IEnumerable < IPlugin > _plugins ;
14- private readonly ILogger _logger ;
15- private readonly IProxyConfiguration _proxyConfiguration ;
16- private readonly ISet < UrlToWatch > _urlsToWatch ;
17- private readonly UpdateNotification _updateNotification ;
18- private WebApplication ? _app ;
14+ private readonly ILogger _logger ;
15+ private readonly IProxyConfiguration _proxyConfiguration ;
16+ private readonly ISet < UrlToWatch > _urlsToWatch ;
17+ private readonly UpdateNotification _updateNotification ;
18+ private WebApplication ? _app ;
19+ private new IReadOnlyList < Option > Options = Array . Empty < Option > ( ) ;
1920
2021 internal const string PortOptionName = "--port" ;
2122 private Option < int ? > ? _portOption ;
@@ -50,24 +51,16 @@ public static string? ConfigFile
5051 {
5152 get
5253 {
53- if ( _configFileOption is null )
54- {
55- _configFileOption = new Option < string ? > ( ConfigFileOptionName , "The path to the configuration file" ) ;
56- _configFileOption . AddAlias ( "-c" ) ;
57- _configFileOption . ArgumentHelpName = "configFile" ;
58- _configFileOption . AddValidator ( input =>
59- {
60- var filePath = ProxyUtils . ReplacePathTokens ( input . Tokens [ 0 ] . Value ) ;
61- if ( string . IsNullOrEmpty ( filePath ) )
62- {
63- return ;
64- }
65-
66- if ( ! File . Exists ( filePath ) )
67- {
68- input . ErrorMessage = $ "Configuration file { filePath } does not exist";
69- }
70- } ) ;
54+ if ( _configFileOption is null )
55+ {
56+ _configFileOption = new Option < string ? > ( ConfigFileOptionName , [ "-c" ] )
57+ {
58+ Description = "The path to the configuration file" ,
59+ HelpName = "configFile"
60+ } ;
61+
62+ // TODO: Fix validation for beta5
63+ // _configFileOption.Validators.Add(input => { ... });
7164 }
7265
7366 var result = _configFileOption . Parse ( Environment . GetCommandLineArgs ( ) ) ;
@@ -105,20 +98,17 @@ public static LogLevel? LogLevel
10598
10699 if ( _logLevelOption is null )
107100 {
108- _logLevelOption = new Option < LogLevel ? > (
109- LogLevelOptionName ,
110- $ "Level of messages to log. Allowed values: { string . Join ( ", " , Enum . GetNames < LogLevel > ( ) ) } "
111- )
112- {
113- ArgumentHelpName = "logLevel"
114- } ;
115- _logLevelOption . AddValidator ( input =>
116- {
117- if ( ! Enum . TryParse < LogLevel > ( input . Tokens [ 0 ] . Value , true , out _ ) )
118- {
119- input . ErrorMessage = $ "{ input . Tokens [ 0 ] . Value } is not a valid log level. Allowed values are: { string . Join ( ", " , Enum . GetNames < LogLevel > ( ) ) } ";
120- }
121- } ) ;
101+ _logLevelOption = new Option < LogLevel ? > (
102+ LogLevelOptionName ,
103+ [ ]
104+ )
105+ {
106+ Description = $ "Level of messages to log. Allowed values: { string . Join ( ", " , Enum . GetNames < LogLevel > ( ) ) } ",
107+ HelpName = "logLevel"
108+ } ;
109+
110+ // TODO: Fix validation for beta5
111+ // _logLevelOption.Validators.Add(input => { ... });
122112 }
123113
124114 var result = _logLevelOption . Parse ( Environment . GetCommandLineArgs ( ) ) ;
@@ -156,17 +146,14 @@ public static string? IPAddress
156146
157147 if ( _ipAddressOption is null )
158148 {
159- _ipAddressOption = new ( IpAddressOptionName , "The IP address for the proxy to bind to" )
160- {
161- ArgumentHelpName = "ipAddress"
162- } ;
163- _ipAddressOption . AddValidator ( input =>
164- {
165- if ( ! System . Net . IPAddress . TryParse ( input . Tokens [ 0 ] . Value , out _ ) )
166- {
167- input . ErrorMessage = $ "{ input . Tokens [ 0 ] . Value } is not a valid IP address";
168- }
169- } ) ;
149+ _ipAddressOption = new ( IpAddressOptionName , [ ] )
150+ {
151+ Description = "The IP address for the proxy to bind to" ,
152+ HelpName = "ipAddress"
153+ } ;
154+
155+ // TODO: Fix validation for beta5
156+ // _ipAddressOption.Validators.Add(input => { ... });
170157 }
171158
172159 var result = _ipAddressOption . Parse ( Environment . GetCommandLineArgs ( ) ) ;
@@ -429,14 +416,18 @@ private void ConfigureCommand()
429416 _discoverOption ,
430417 _envOption
431418 } ;
432- options . AddRange ( _plugins
433- . SelectMany ( p => p . GetOptions ( ) )
434- // remove duplicates by comparing the option names
435- . GroupBy ( o => o . Name )
436- . Select ( g => g . First ( ) ) ) ;
437- this . AddOptions ( options . OrderByName ( ) ) ;
438-
439- AddGlobalOption ( _logLevelOption ! ) ;
419+ options . AddRange ( _plugins
420+ . SelectMany ( p => p . GetOptions ( ) )
421+ // remove duplicates by comparing the option names
422+ . GroupBy ( o => o . Name )
423+ . Select ( g => g . First ( ) ) ) ;
424+ this . AddOptions ( options . OrderByName ( ) ) ;
425+
426+ // Store options for use in parsing methods
427+ Options = options . AsReadOnly ( ) ;
428+
429+ // Add log level as a regular option instead of global option
430+ // In beta5, global options are handled by adding to the root command
440431
441432 var commands = new List < Command >
442433 {
0 commit comments