/// <summary> /// Constructor. /// </summary> /// <param name="argSet">Argument set to create parser for.</param> /// <param name="options">Parser options.</param> public ArgumentSetParser(ArgumentSetDefinition argSet, CommandLineParserOptions options) { if (argSet == null) { throw new ArgumentNullException(nameof(argSet)); } // Clone the argument set definition, as parsing may mutate it. ArgumentSet = argSet.DeepClone(); // Save off the options provided; if none were provided, construct some quiet defaults. _options = options?.DeepClone() ?? CommandLineParserOptions.Quiet(); // If no reporter was provided, use a no-op one. if (_options.Reporter == null) { _options.Reporter = err => { }; } // If no file-system reader was provided, use our default implementation. if (_options.FileSystemReader == null) { _options.FileSystemReader = FileSystemReader.Create(); } }
/// <summary> /// Checks if the empty string is a valid value for this argument. /// </summary> /// <param name="parserOptions">Parser options.</param> /// <returns>true if it is valid; false otherwise.</returns> internal bool IsEmptyStringValid(CommandLineParserOptions parserOptions) { var options = parserOptions.DeepClone().With().Quiet().Apply(); var parseState = new ArgumentParser(ContainingSet, this, options, /*destination=*/ null); return(ArgumentType.TryParse(parseState.ParseContext, string.Empty, out object parsedEmptyString) && parseState.TryValidateValue( parsedEmptyString, new ArgumentValidationContext(parseState.ParseContext.FileSystemReader), reportInvalidValue: false)); }