Class OptionParseResult
Represents the outcome of parsing a command line.
public sealed class OptionParseResult
- Inheritance
-
OptionParseResult
- Inherited Members
Constructors
OptionParseResult(OptionSet, IReadOnlyList<LogEntry>, bool, int, bool, bool)
Creates a parse result from parsed options and recorded diagnostics.
public OptionParseResult(OptionSet options, IReadOnlyList<LogEntry> diagnostics, bool wasHandled, int exitCode, bool wasHelpRequested, bool wasVersionRequested)
Parameters
optionsOptionSetThe parsed options.
diagnosticsIReadOnlyList<LogEntry>The diagnostics emitted while parsing.
wasHandledboolTells if parsing already handled a conventional exit path, such as printing generated help or version information.
exitCodeintThe recommended process exit code.
wasHelpRequestedboolTells if the help option was requested.
wasVersionRequestedboolTells if the version option was requested.
Properties
Diagnostics
Gets the diagnostics emitted while parsing.
public IReadOnlyList<LogEntry> Diagnostics { get; }
Property Value
- IReadOnlyList<LogEntry>
The diagnostics emitted while parsing.
ExitCode
Gets the exit code associated with this parse result.
public int ExitCode { get; }
Property Value
- int
The recommended exit code.
IsSuccess
Tells if parsing succeeded without errors.
public bool IsSuccess { get; }
Property Value
- bool
trueif no errors were emitted while parsing; otherwise,false.
Options
Gets the parsed options.
public OptionSet Options { get; }
Property Value
- OptionSet
The parsed options.
WasHandled
Tells if parsing already handled a conventional exit path,
such as printing generated help or version information.
This is typically true when WasHelpRequested
or WasVersionRequested is true.
It is typically false for ordinary successful parses,
where the caller should continue running the command, and also
for parse failures, where IsSuccess is false.
public bool WasHandled { get; }
Property Value
- bool
trueif parsing printed a built-in terminal response and the caller will usually want to return immediately; otherwise,false.
WasHelpRequested
Tells if the help option was requested.
public bool WasHelpRequested { get; }
Property Value
- bool
trueif help was requested; otherwise,false.
WasVersionRequested
Tells if the version option was requested.
public bool WasVersionRequested { get; }
Property Value
- bool
trueif version information was requested; otherwise,false.
Methods
Contains(Severity)
Tests if parsing emitted at least one diagnostic of a particular severity.
public bool Contains(Severity severity)
Parameters
severitySeverityThe severity to look for.
Returns
- bool
trueif parsing emitted a diagnostic of the requested severity; otherwise,false.
GetValue(FlagOption)
Gets the Boolean value that has been parsed for a flag option. If there is no such value, then the flag's default value is returned.
public bool GetValue(FlagOption opt)
Parameters
optFlagOptionA flag option to find a parsed value for.
Returns
- bool
The parsed value or the flag's default value.
GetValue<T>(Option)
Gets the value that has been parsed for a particular option. If there is no such value, then the option's default value is returned.
public T GetValue<T>(Option opt)
Parameters
optOptionAn option to find a parsed value for.
Returns
- T
The parsed value or the option's default value.
Type Parameters
TThe option's value type.
GetValue<T>(SequenceOption<T>)
Gets the values that have been parsed for a typed sequence option. If there is no such value, then the option's default value is returned.
public IReadOnlyList<T> GetValue<T>(SequenceOption<T> opt)
Parameters
optSequenceOption<T>A typed sequence option to find parsed values for.
Returns
- IReadOnlyList<T>
The parsed values or the option's default value.
Type Parameters
TThe option's element type.
GetValue<T>(ValueOption<T>)
Gets the value that has been parsed for a typed value option. If there is no such value, then the option's default value is returned.
public T GetValue<T>(ValueOption<T> opt)
Parameters
optValueOption<T>A typed value option to find a parsed value for.
Returns
- T
The parsed value or the option's default value.
Type Parameters
TThe option's value type.
TryGetValue(FlagOption, out bool)
Looks for the Boolean value that has been parsed for a flag option. If there is no such value, then the flag's default value is produced.
public bool TryGetValue(FlagOption opt, out bool result)
Parameters
optFlagOptionA flag option to find a parsed value for.
resultboolThe resulting Boolean value.
Returns
- bool
trueif a form of the flag has been parsed; otherwise,false.
TryGetValue<T>(Option, out T)
Looks for the value that has been parsed for a particular option. If there is no such value, then the option's default value is produced.
public bool TryGetValue<T>(Option opt, out T result)
Parameters
optOptionAn option to find a parsed value for.
resultTThe resulting value.
Returns
- bool
trueif a form of the option has been parsed; otherwise,false.
Type Parameters
TThe option's value type.
TryGetValue<T>(SequenceOption<T>, out IReadOnlyList<T>)
Looks for the values that have been parsed for a typed sequence option. If there is no such value, then the option's default value is produced.
public bool TryGetValue<T>(SequenceOption<T> opt, out IReadOnlyList<T> result)
Parameters
optSequenceOption<T>A typed sequence option to find parsed values for.
resultIReadOnlyList<T>The resulting sequence of values.
Returns
- bool
trueif a form of the option has been parsed; otherwise,false.
Type Parameters
TThe option's element type.
TryGetValue<T>(ValueOption<T>, out T)
Looks for the value that has been parsed for a typed value option. If there is no such value, then the option's default value is produced.
public bool TryGetValue<T>(ValueOption<T> opt, out T result)
Parameters
optValueOption<T>A typed value option to find a parsed value for.
resultTThe resulting value.
Returns
- bool
trueif a form of the option has been parsed; otherwise,false.
Type Parameters
TThe option's value type.