BadScript 2
Loading...
Searching...
No Matches
CommandLine.ParserSettings Class Reference

Provides settings for CommandLine.Parser. Once consumed cannot be reused. More...

Inheritance diagram for CommandLine.ParserSettings:

Public Member Functions

 ParserSettings (int? maxDisplayWidth=null)
 Initializes a new instance of the ParserSettings class.
 
void Dispose ()
 Frees resources owned by the instance.
 

Static Public Member Functions

static ParserSettings CreateDefault (int? maxDisplayWidth=null)
 

Static Public Attributes

const int DefaultMaximumLength = 80
 

Properties

bool CaseSensitive [get, set]
 Gets or sets a value indicating whether perform case sensitive comparisons. Note that case insensitivity only applies to parameters, not the values assigned to them (for example, enum parsing).
 
bool CaseInsensitiveEnumValues [get, set]
 Gets or sets a value indicating whether perform case sensitive comparisons of values. Note that case insensitivity only applies to values, not the parameters.
 
CultureInfo ParsingCulture [get, set]
 Gets or sets the culture used when parsing arguments to typed properties.
 
TextWriter HelpWriter [get, set]
 Gets or sets the System.IO.TextWriter used for help method output. Setting this property to null, will disable help screen.
 
bool IgnoreUnknownArguments [get, set]
 Gets or sets a value indicating whether the parser shall move on to the next argument and ignore the given argument if it encounter an unknown arguments.
 
bool AutoHelp [get, set]
 Gets or sets a value indicating whether implicit option or verb 'help' should be supported.
 
bool AutoVersion [get, set]
 Gets or sets a value indicating whether implicit option or verb 'version' should be supported.
 
bool EnableDashDash [get, set]
 Gets or sets a value indicating whether enable double dash '–' syntax, that forces parsing of all subsequent tokens as values. If GetoptMode is true, this defaults to true, but can be turned off by explicitly specifying EnableDashDash = false.
 
int MaximumDisplayWidth [get, set]
 Gets or sets the maximum width of the display. This determines word wrap when displaying the text.
 
bool AllowMultiInstance [get, set]
 Gets or sets a value indicating whether options are allowed to be specified multiple times. If GetoptMode is true, this defaults to true, but can be turned off by explicitly specifying AllowMultiInstance = false.
 
bool GetoptMode [get, set]
 Whether strict getopt-like processing is applied to option values; if true, AllowMultiInstance and EnableDashDash will default to true as well.
 
bool PosixlyCorrect [get, set]
 Whether getopt-like processing should follow the POSIX rules (the equivalent of using the "+" prefix in the C getopt() call). If not explicitly set, will default to false unless the POSIXLY_CORRECT environment variable is set, in which case it will default to true.
 
StringComparer NameComparer [get]
 
bool Consumed [get, set]
 

Private Member Functions

int GetWindowWidth ()
 
 ~ParserSettings ()
 Finalizes an instance of the CommandLine.ParserSettings class.
 
void Dispose (bool disposing)
 

Private Attributes

Maybe< bool > allowMultiInstance
 
bool autoHelp
 
bool autoVersion
 
bool caseInsensitiveEnumValues
 
bool caseSensitive
 
bool disposed
 
Maybe< bool > enableDashDash
 
bool getoptMode
 
TextWriter helpWriter
 
bool ignoreUnknownArguments
 
CultureInfo parsingCulture
 
Maybe< bool > posixlyCorrect
 

Detailed Description

Provides settings for CommandLine.Parser. Once consumed cannot be reused.

Definition at line 16 of file ParserSettings.cs.

Constructor & Destructor Documentation

◆ ParserSettings()

CommandLine.ParserSettings.ParserSettings ( int?  maxDisplayWidth = null)

Initializes a new instance of the ParserSettings class.

Definition at line 36 of file ParserSettings.cs.

37 {
38 caseSensitive = true;
40 autoHelp = true;
41 autoVersion = true;
42 parsingCulture = CultureInfo.InvariantCulture;
43 MaximumDisplayWidth = maxDisplayWidth ?? GetWindowWidth();
44 getoptMode = false;
45 enableDashDash = Maybe.Nothing<bool>();
46 allowMultiInstance = Maybe.Nothing<bool>();
47 posixlyCorrect = Maybe.Nothing<bool>();
48 }
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
int MaximumDisplayWidth
Gets or sets the maximum width of the display. This determines word wrap when displaying the text.

◆ ~ParserSettings()

CommandLine.ParserSettings.~ParserSettings ( )
private

Finalizes an instance of the CommandLine.ParserSettings class.

Definition at line 251 of file ParserSettings.cs.

252 {
253 Dispose(false);
254 }
void Dispose()
Frees resources owned by the instance.

Member Function Documentation

◆ CreateDefault()

static ParserSettings CommandLine.ParserSettings.CreateDefault ( int?  maxDisplayWidth = null)
static

Definition at line 214 of file ParserSettings.cs.

215 {
216 return new ParserSettings(maxDisplayWidth);
217 }
ParserSettings(int? maxDisplayWidth=null)
Initializes a new instance of the ParserSettings class.

◆ Dispose() [1/2]

void CommandLine.ParserSettings.Dispose ( )

Frees resources owned by the instance.

Definition at line 205 of file ParserSettings.cs.

206 {
207 Dispose(true);
208
209 GC.SuppressFinalize(this);
210 }

◆ Dispose() [2/2]

void CommandLine.ParserSettings.Dispose ( bool  disposing)
private

Definition at line 256 of file ParserSettings.cs.

257 {
258 if (disposed)
259 {
260 return;
261 }
262
263 if (disposing)
264 {
265 // Do not dispose HelpWriter. It is the caller's responsibility.
266
267 disposed = true;
268 }
269 }

◆ GetWindowWidth()

int CommandLine.ParserSettings.GetWindowWidth ( )
private

Definition at line 219 of file ParserSettings.cs.

220 {
221#if !NET40
222 if (Console.IsOutputRedirected)
223 {
225 }
226#endif
227 int width = 1;
228
229 try
230 {
231 width = Console.WindowWidth;
232
233 if (width < 1)
234 {
235 width = DefaultMaximumLength;
236 }
237 }
238 catch (Exception e) when (e is IOException ||
239 e is PlatformNotSupportedException ||
240 e is ArgumentOutOfRangeException)
241 {
242 width = DefaultMaximumLength;
243 }
244
245 return width;
246 }

Member Data Documentation

◆ allowMultiInstance

Maybe<bool> CommandLine.ParserSettings.allowMultiInstance
private

Definition at line 19 of file ParserSettings.cs.

◆ autoHelp

bool CommandLine.ParserSettings.autoHelp
private

Definition at line 20 of file ParserSettings.cs.

◆ autoVersion

bool CommandLine.ParserSettings.autoVersion
private

Definition at line 21 of file ParserSettings.cs.

◆ caseInsensitiveEnumValues

bool CommandLine.ParserSettings.caseInsensitiveEnumValues
private

Definition at line 22 of file ParserSettings.cs.

◆ caseSensitive

bool CommandLine.ParserSettings.caseSensitive
private

Definition at line 23 of file ParserSettings.cs.

◆ DefaultMaximumLength

const int CommandLine.ParserSettings.DefaultMaximumLength = 80
static

Definition at line 18 of file ParserSettings.cs.

◆ disposed

bool CommandLine.ParserSettings.disposed
private

Definition at line 25 of file ParserSettings.cs.

◆ enableDashDash

Maybe<bool> CommandLine.ParserSettings.enableDashDash
private

Definition at line 26 of file ParserSettings.cs.

◆ getoptMode

bool CommandLine.ParserSettings.getoptMode
private

Definition at line 27 of file ParserSettings.cs.

◆ helpWriter

TextWriter CommandLine.ParserSettings.helpWriter
private

Definition at line 28 of file ParserSettings.cs.

◆ ignoreUnknownArguments

bool CommandLine.ParserSettings.ignoreUnknownArguments
private

Definition at line 29 of file ParserSettings.cs.

◆ parsingCulture

CultureInfo CommandLine.ParserSettings.parsingCulture
private

Definition at line 30 of file ParserSettings.cs.

◆ posixlyCorrect

Maybe<bool> CommandLine.ParserSettings.posixlyCorrect
private

Definition at line 31 of file ParserSettings.cs.

Property Documentation

◆ AllowMultiInstance

bool CommandLine.ParserSettings.AllowMultiInstance
getset

Gets or sets a value indicating whether options are allowed to be specified multiple times. If GetoptMode is true, this defaults to true, but can be turned off by explicitly specifying AllowMultiInstance = false.

Definition at line 163 of file ParserSettings.cs.

164 {
165 get => allowMultiInstance.MatchJust(out bool value) ? value : getoptMode;
166 set => PopsicleSetter.Set(Consumed, ref allowMultiInstance, Maybe.Just(value));
167 }
bool MatchJust(out T value)
Matches a value returning true and value itself via output parameter.
Definition Maybe.cs:49

◆ AutoHelp

bool CommandLine.ParserSettings.AutoHelp
getset

Gets or sets a value indicating whether implicit option or verb 'help' should be supported.

Definition at line 126 of file ParserSettings.cs.

127 {
128 get => autoHelp;
129 set => PopsicleSetter.Set(Consumed, ref autoHelp, value);
130 }

◆ AutoVersion

bool CommandLine.ParserSettings.AutoVersion
getset

Gets or sets a value indicating whether implicit option or verb 'version' should be supported.

Definition at line 135 of file ParserSettings.cs.

136 {
137 get => autoVersion;
138 set => PopsicleSetter.Set(Consumed, ref autoVersion, value);
139 }

◆ CaseInsensitiveEnumValues

bool CommandLine.ParserSettings.CaseInsensitiveEnumValues
getset

Gets or sets a value indicating whether perform case sensitive comparisons of values. Note that case insensitivity only applies to values, not the parameters.

Definition at line 65 of file ParserSettings.cs.

66 {
69 }

◆ CaseSensitive

bool CommandLine.ParserSettings.CaseSensitive
getset

Gets or sets a value indicating whether perform case sensitive comparisons. Note that case insensitivity only applies to parameters, not the values assigned to them (for example, enum parsing).

Definition at line 55 of file ParserSettings.cs.

56 {
57 get => caseSensitive;
58 set => PopsicleSetter.Set(Consumed, ref caseSensitive, value);
59 }

◆ Consumed

bool CommandLine.ParserSettings.Consumed
getsetpackage

Definition at line 198 of file ParserSettings.cs.

198{ get; set; }

◆ EnableDashDash

bool CommandLine.ParserSettings.EnableDashDash
getset

Gets or sets a value indicating whether enable double dash '–' syntax, that forces parsing of all subsequent tokens as values. If GetoptMode is true, this defaults to true, but can be turned off by explicitly specifying EnableDashDash = false.

Definition at line 147 of file ParserSettings.cs.

148 {
149 get => enableDashDash.MatchJust(out bool value) ? value : getoptMode;
150 set => PopsicleSetter.Set(Consumed, ref enableDashDash, Maybe.Just(value));
151 }

◆ GetoptMode

bool CommandLine.ParserSettings.GetoptMode
getset

Whether strict getopt-like processing is applied to option values; if true, AllowMultiInstance and EnableDashDash will default to true as well.

Definition at line 173 of file ParserSettings.cs.

174 {
175 get => getoptMode;
176 set => PopsicleSetter.Set(Consumed, ref getoptMode, value);
177 }

◆ HelpWriter

TextWriter CommandLine.ParserSettings.HelpWriter
getset

Gets or sets the System.IO.TextWriter used for help method output. Setting this property to null, will disable help screen.

It is the caller's responsibility to dispose or close the TextWriter.

Definition at line 98 of file ParserSettings.cs.

99 {
100 get => helpWriter;
101 set => PopsicleSetter.Set(Consumed, ref helpWriter, value);
102 }

◆ IgnoreUnknownArguments

bool CommandLine.ParserSettings.IgnoreUnknownArguments
getset

Gets or sets a value indicating whether the parser shall move on to the next argument and ignore the given argument if it encounter an unknown arguments.

true to allow parsing the arguments with different class options that do not have all the arguments.

This allows fragmented version class parsing, useful for project with add-on where add-ons also requires command line arguments but when these are unknown by the main program at build time.

Definition at line 117 of file ParserSettings.cs.

118 {
120 set => PopsicleSetter.Set(Consumed, ref ignoreUnknownArguments, value);
121 }

◆ MaximumDisplayWidth

int CommandLine.ParserSettings.MaximumDisplayWidth
getset

Gets or sets the maximum width of the display. This determines word wrap when displaying the text.

Definition at line 156 of file ParserSettings.cs.

156{ get; set; }

◆ NameComparer

StringComparer CommandLine.ParserSettings.NameComparer
getpackage

Definition at line 194 of file ParserSettings.cs.

◆ ParsingCulture

CultureInfo CommandLine.ParserSettings.ParsingCulture
getset

Gets or sets the culture used when parsing arguments to typed properties.

Default is invariant culture, System.Globalization.CultureInfo.InvariantCulture.

Definition at line 77 of file ParserSettings.cs.

78 {
79 get => parsingCulture;
80 set
81 {
82 if (value == null)
83 {
84 throw new ArgumentNullException("value");
85 }
86
87 PopsicleSetter.Set(Consumed, ref parsingCulture, value);
88 }
89 }

◆ PosixlyCorrect

bool CommandLine.ParserSettings.PosixlyCorrect
getset

Whether getopt-like processing should follow the POSIX rules (the equivalent of using the "+" prefix in the C getopt() call). If not explicitly set, will default to false unless the POSIXLY_CORRECT environment variable is set, in which case it will default to true.

Definition at line 185 of file ParserSettings.cs.

186 {
187 get => posixlyCorrect.MapValueOrDefault(val => val,
188 () => Environment.GetEnvironmentVariable("POSIXLY_CORRECT")
189 .ToBooleanLoose()
190 );
191 set => PopsicleSetter.Set(Consumed, ref posixlyCorrect, Maybe.Just(value));
192 }

The documentation for this class was generated from the following file: