@@ -29,12 +29,13 @@ internal static class ServerSettingsManager
29
29
/// then overridden by any options specified in the command line arguments (if any).
30
30
/// </summary>
31
31
/// <param name="args">Command line arguments</param>
32
- /// <param name="logger">Logger</param>
33
32
/// <param name="options">Options object containing parsed configuration settings</param>
34
33
/// <param name="invalidOptions">List of Options properties that did not pass validation</param>
35
34
/// <param name="exitGracefully">True if should exit gracefully when parse is unsuccessful</param>
35
+ /// <param name="silentMode">If true, help text will not be printed to console when parse is unsuccessful</param>
36
+ /// <param name="logger">Logger</param>
36
37
/// <returns>True if parsing succeeded</returns>
37
- internal static bool TryParseCommandLineArguments ( string [ ] args , out Options options , out List < string > invalidOptions , out bool exitGracefully , ILogger logger = null )
38
+ internal static bool TryParseCommandLineArguments ( string [ ] args , out Options options , out List < string > invalidOptions , out bool exitGracefully , bool silentMode = false , ILogger logger = null )
38
39
{
39
40
options = null ;
40
41
invalidOptions = [ ] ;
@@ -63,7 +64,7 @@ internal static bool TryParseCommandLineArguments(string[] args, out Options opt
63
64
64
65
var consolidatedArgs = ConsolidateFlagArguments ( args ) ;
65
66
// Parse command line arguments
66
- if ( ! parser . TryParseArguments < Options > ( consolidatedArgs , argNameToDefaultValue , out var cmdLineOptions , out exitGracefully ) )
67
+ if ( ! parser . TryParseArguments < Options > ( consolidatedArgs , argNameToDefaultValue , out var cmdLineOptions , out exitGracefully , silentMode : silentMode ) )
67
68
return false ;
68
69
69
70
// Check if any arguments were not parsed
@@ -114,7 +115,7 @@ internal static bool TryParseCommandLineArguments(string[] args, out Options opt
114
115
115
116
// Re-parse command line arguments after initializing Options object with initialization function
116
117
// In order to override options specified in the command line arguments
117
- if ( ! parser . TryParseArguments ( consolidatedArgs , argNameToDefaultValue , out options , out exitGracefully , ( ) => initOptions ) )
118
+ if ( ! parser . TryParseArguments ( consolidatedArgs , argNameToDefaultValue , out options , out exitGracefully , ( ) => initOptions , silentMode ) )
118
119
return false ;
119
120
120
121
// Validate options
@@ -175,15 +176,19 @@ private static Dictionary<string, object> GetArgumentNameToValue(Options options
175
176
/// <param name="obj">Parsed object, default(T) if parse unsuccessful</param>
176
177
/// <param name="exitGracefully">True if should exit gracefully when parse is unsuccessful</param>
177
178
/// <param name="factory">Optional T factory for object initialization</param>
179
+ /// <param name="silentMode">If true, help messages will not be printed to console.</param>
178
180
/// <returns>True if parse successful</returns>
179
- private static bool TryParseArguments < T > ( this Parser parser , string [ ] args , IDictionary < string , object > argNameToDefaultValue , out T obj , out bool exitGracefully , Func < T > factory = null ) where T : new ( )
181
+ private static bool TryParseArguments < T > ( this Parser parser , string [ ] args , IDictionary < string , object > argNameToDefaultValue , out T obj , out bool exitGracefully , Func < T > factory = null , bool silentMode = false ) where T : new ( )
180
182
{
181
183
var result = parser . ParseArguments ( factory ?? ( ( ) => new T ( ) ) , args ) ;
182
184
var tmpExitGracefully = true ;
183
185
184
186
obj = result . MapResult ( parsed => parsed ,
185
187
notParsed =>
186
188
{
189
+ if ( silentMode )
190
+ return default ;
191
+
187
192
var errors = notParsed . ToList ( ) ;
188
193
if ( errors . IsVersion ( ) ) // Check if error is version request
189
194
{
0 commit comments