4using System.Collections.Generic;
43 public Parser(Action<ParserSettings> configuration)
45 if (configuration ==
null)
47 throw new ArgumentNullException(
"configuration");
52 Settings.Consumed =
true;
55 public Parser(Func<ParserSettings> factory)
59 throw new ArgumentNullException(nameof(factory));
63 Settings.Consumed =
true;
69 Settings.Consumed =
true;
82#region IDisposable Members
91 GC.SuppressFinalize(
this);
124 throw new ArgumentNullException(
"args");
128 ?
Maybe.Just<Func<T>>(Activator.CreateInstance<T>)
129 :
Maybe.Nothing<Func<T>>();
132 (arguments, optionSpecs) =>
168 throw new ArgumentNullException(
"factory");
171 if (!typeof(T).IsMutable())
173 throw new ArgumentException(
"factory");
178 throw new ArgumentNullException(
"args");
182 (arguments, optionSpecs) =>
220 throw new ArgumentNullException(
"args");
225 throw new ArgumentNullException(
"types");
228 if (types.Length == 0)
230 throw new ArgumentOutOfRangeException(
"types");
250 IEnumerable<OptionSpecification> optionSpecs,
253 return settings.GetoptMode
258 )(arguments, optionSpecs)
262 )(arguments, optionSpecs);
267 return DisplayHelp(parserResult,
274 TextWriter helpWriter,
277 parserResult.WithNotParsed(errors =>
278 Maybe.Merge(errors.ToMaybe(), helpWriter.ToMaybe())
280 writer.Write(
HelpText.AutoBuild(parserResult, maxDisplayWidth))
289 return ignoreUnknownArguments
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
static Func< IEnumerable< string >, IEnumerable< OptionSpecification >, Result< IEnumerable< Token >, Error > > ConfigureTokenizer(StringComparer nameComparer, bool ignoreUnknownArguments, bool enableDashDash, bool posixlyCorrect)
static ParserResult< object > Choose(Func< IEnumerable< string >, IEnumerable< OptionSpecification >, Result< IEnumerable< Token >, Error > > tokenizer, IEnumerable< Type > types, IEnumerable< string > arguments, StringComparer nameComparer, bool ignoreValueCase, CultureInfo parsingCulture, bool autoHelp, bool autoVersion, IEnumerable< ErrorType > nonFatalErrors)
static Func< IEnumerable< string >, IEnumerable< OptionSpecification >, Result< IEnumerable< Token >, Error > > ConfigureTokenizer(StringComparer nameComparer, bool ignoreUnknownArguments, bool enableDashDash)
Provides methods to parse command line arguments.
static ParserResult< T > MakeParserResult< T >(ParserResult< T > parserResult, ParserSettings settings)
void Dispose()
Frees resources owned by the instance.
static readonly Lazy< Parser > DefaultParser
void Dispose(bool disposing)
Parser(ParserSettings settings)
Parser(Action< ParserSettings > configuration)
Initializes a new instance of the Parser class, configurable with ParserSettings using a delegate.
~Parser()
Finalizes an instance of the CommandLine.Parser class.
ParserResult< T > ParseArguments< T >(IEnumerable< string > args)
Parses a string array of command line arguments constructing values in an instance of type T ....
ParserSettings Settings
Gets the instance that implements CommandLine.ParserSettings in use.
static ParserResult< T > DisplayHelp< T >(ParserResult< T > parserResult, TextWriter helpWriter, int maxDisplayWidth)
Parser()
Initializes a new instance of the CommandLine.Parser class.
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
static Result< IEnumerable< Token >, Error > Tokenize(IEnumerable< string > arguments, IEnumerable< OptionSpecification > optionSpecs, ParserSettings settings)
static Parser Default
Gets the singleton instance created with basic defaults.
Parser(Func< ParserSettings > factory)
static IEnumerable< ErrorType > HandleUnknownArguments(bool ignoreUnknownArguments)
Models a parser result. When inherited by CommandLine.Parsed<T>, it contains an instance of type T w...
Provides settings for CommandLine.Parser. Once consumed cannot be reused.
bool PosixlyCorrect
Whether getopt-like processing should follow the POSIX rules (the equivalent of using the "+" prefix ...
int MaximumDisplayWidth
Gets or sets the maximum width of the display. This determines word wrap when displaying the text.
bool EnableDashDash
Gets or sets a value indicating whether enable double dash '–' syntax, that forces parsing of all sub...
bool AllowMultiInstance
Gets or sets a value indicating whether options are allowed to be specified multiple times....
bool CaseInsensitiveEnumValues
Gets or sets a value indicating whether perform case sensitive comparisons of values....
bool AutoHelp
Gets or sets a value indicating whether implicit option or verb 'help' should be supported.
void Dispose()
Frees resources owned by the instance.
bool IgnoreUnknownArguments
Gets or sets a value indicating whether the parser shall move on to the next argument and ignore the ...
CultureInfo ParsingCulture
Gets or sets the culture used when parsing arguments to typed properties.
StringComparer NameComparer
TextWriter HelpWriter
Gets or sets the System.IO.TextWriter used for help method output. Setting this property to null,...
bool AutoVersion
Gets or sets a value indicating whether implicit option or verb 'version' should be supported.
Represents the result of a computation.
ErrorType
Discriminator enumeration of CommandLine.Error derivates.