@@ -51,7 +51,7 @@ static CommandLineApplication()
51
51
private readonly HashSet < string > _names = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
52
52
private string ? _primaryCommandName ;
53
53
internal CommandLineContext _context ;
54
- private ParserConfig _parserConfig ;
54
+ private readonly ParserConfig _parserConfig ;
55
55
private IHelpTextGenerator _helpTextGenerator ;
56
56
private CommandOption ? _optionHelp ;
57
57
private readonly Lazy < IServiceProvider > _services ;
@@ -224,11 +224,9 @@ public CommandOption? OptionHelp
224
224
{
225
225
return _optionHelp ;
226
226
}
227
- if ( Parent ? . OptionHelp ? . Inherited == true )
228
- {
229
- return Parent . OptionHelp ;
230
- }
231
- return null ;
227
+ return Parent ? . OptionHelp ? . Inherited == true
228
+ ? Parent . OptionHelp
229
+ : null ;
232
230
}
233
231
internal set => _optionHelp = value ;
234
232
}
@@ -245,7 +243,7 @@ public CommandOption? OptionHelp
245
243
public List < CommandArgument > Arguments { get ; private set ; }
246
244
247
245
/// <summary>
248
- /// When initialized when <see cref="UnrecognizedArgumentHandling"/> is <see cref="UnrecognizedArgumentHandling.StopParsingAndCollect" />,
246
+ /// When initialized when <see cref="UnrecognizedArgumentHandling"/> is <see cref="McMaster.Extensions.CommandLineUtils. UnrecognizedArgumentHandling.StopParsingAndCollect" />,
249
247
/// this will contain any unrecognized arguments.
250
248
/// </summary>
251
249
public List < string > RemainingArguments { get ; private set ; }
@@ -290,7 +288,7 @@ public UnrecognizedArgumentHandling UnrecognizedArgumentHandling
290
288
/// A response file contains additional arguments that will be treated as if they were passed in on the command line.
291
289
/// </para>
292
290
/// <para>
293
- /// Defaults to <see cref="ResponseFileHandling.Disabled" />.
291
+ /// Defaults to <see cref="McMaster.Extensions.CommandLineUtils. ResponseFileHandling.Disabled" />.
294
292
/// </para>
295
293
/// <para>
296
294
/// Nested response false are not supported.
@@ -359,19 +357,16 @@ public char[] OptionNameValueSeparators
359
357
get => _parserConfig . OptionNameValueSeparators ?? Parent ? . OptionNameValueSeparators ?? new [ ] { ' ' , ':' , '=' } ;
360
358
set
361
359
{
362
- if ( value is null )
363
- {
364
- throw new ArgumentNullException ( nameof ( value ) ) ;
365
- }
366
- else if ( value . Length == 0 )
360
+ if ( value . Length == 0 )
367
361
{
368
362
throw new ArgumentException ( Strings . IsEmptyArray , nameof ( value ) ) ;
369
363
}
364
+
370
365
_parserConfig . OptionNameValueSeparators = value ;
371
366
}
372
367
}
373
368
374
- internal bool OptionNameAndValueCanBeSpaceSeparated => Array . IndexOf ( this . OptionNameValueSeparators , ' ' ) >= 0 ;
369
+ internal bool OptionNameAndValueCanBeSpaceSeparated => Array . IndexOf ( OptionNameValueSeparators , ' ' ) >= 0 ;
375
370
376
371
/// <summary>
377
372
/// Gets the default value parser provider.
@@ -920,14 +915,9 @@ public CommandOption VersionOption(string template,
920
915
string ? shortFormVersion ,
921
916
string ? longFormVersion = null )
922
917
{
923
- if ( longFormVersion == null )
924
- {
925
- return VersionOption ( template , ( ) => shortFormVersion ) ;
926
- }
927
- else
928
- {
929
- return VersionOption ( template , ( ) => shortFormVersion , ( ) => longFormVersion ) ;
930
- }
918
+ return longFormVersion == null
919
+ ? VersionOption ( template , ( ) => shortFormVersion )
920
+ : VersionOption ( template , ( ) => shortFormVersion , ( ) => longFormVersion ) ;
931
921
}
932
922
933
923
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
@@ -980,7 +970,7 @@ public virtual void ShowHint()
980
970
/// <param name="usePager">Use a console pager to display help text, if possible.</param>
981
971
public void ShowHelp ( bool usePager )
982
972
{
983
- CommandLineApplication ? cmd = this ;
973
+ var cmd = this ;
984
974
while ( cmd != null )
985
975
{
986
976
cmd . IsShowingInformation = true ;
@@ -1015,7 +1005,7 @@ public virtual string GetHelpText()
1015
1005
/// </summary>
1016
1006
public void ShowVersion ( )
1017
1007
{
1018
- CommandLineApplication ? cmd = this ;
1008
+ var cmd = this ;
1019
1009
while ( cmd != null )
1020
1010
{
1021
1011
cmd . IsShowingInformation = true ;
@@ -1077,12 +1067,7 @@ public void ShowRootCommandFullNameAndVersion()
1077
1067
1078
1068
internal bool MatchesName ( string name )
1079
1069
{
1080
- if ( string . Equals ( name , Name , StringComparison . OrdinalIgnoreCase ) )
1081
- {
1082
- return true ;
1083
- }
1084
-
1085
- return _names . Contains ( name ) ;
1070
+ return string . Equals ( name , Name , StringComparison . OrdinalIgnoreCase ) || _names . Contains ( name ) ;
1086
1071
}
1087
1072
1088
1073
private sealed class Builder : IConventionBuilder
@@ -1113,17 +1098,7 @@ IConventionBuilder IConventionBuilder.AddConvention(IConvention convention)
1113
1098
/// <summary>
1114
1099
/// Gets a builder that can be used to apply conventions to
1115
1100
/// </summary>
1116
- public IConventionBuilder Conventions
1117
- {
1118
- get
1119
- {
1120
- if ( _builder == null )
1121
- {
1122
- _builder = new Builder ( this ) ;
1123
- }
1124
- return _builder ;
1125
- }
1126
- }
1101
+ public IConventionBuilder Conventions => _builder ??= new Builder ( this ) ;
1127
1102
1128
1103
private protected virtual ConventionContext CreateConventionContext ( ) => new ConventionContext ( this , null ) ;
1129
1104
@@ -1192,7 +1167,7 @@ public ServiceProvider(CommandLineApplication parent)
1192
1167
return _parent ;
1193
1168
}
1194
1169
1195
- // prefer this type before AdditionalServces because it is common for service containers to automatically
1170
+ // prefer this type before AdditionalServices because it is common for service containers to automatically
1196
1171
// create IEnumerable<T> to allow registration of multiple services
1197
1172
if ( serviceType == typeof ( IEnumerable < CommandOption > ) )
1198
1173
{
@@ -1219,13 +1194,10 @@ public ServiceProvider(CommandLineApplication parent)
1219
1194
return accessor . GetModel ( ) ;
1220
1195
}
1221
1196
1222
- if ( _parent . AdditionalServices != null )
1197
+ var retVal = _parent . AdditionalServices ? . GetService ( serviceType ) ;
1198
+ if ( retVal != null )
1223
1199
{
1224
- var retVal = _parent . AdditionalServices . GetService ( serviceType ) ;
1225
- if ( retVal != null )
1226
- {
1227
- return retVal ;
1228
- }
1200
+ return retVal ;
1229
1201
}
1230
1202
1231
1203
// Resolve this after AdditionalServices to support overriding IConsole from a custom service container
0 commit comments