PeanutButter
Loading...
Searching...
No Matches
PeanutButter.EasyArgs.ParserOptions Class Reference

Provides options for the parser. More...

Public Member Functions

virtual void ReportMultipleValuesForSingleValueArgument (string arg)
 Reports that multiple values were found for a single-value argument.
virtual void ReportMissingFile (string arg, string value)
 Reports when an expected file is missing.
virtual void ReportConflict (string left, string right)
 Reports that two conflicting arguments were specified.
virtual void ReportUnknownSwitch (string arg)
 Reports that an unknown switch was encountered.
virtual void DisplayHelp< T > (CommandlineArgument[] options)
 Displays help via the LineWriter action.
virtual void ReportMissingRequiredOption (CommandlineArgument arg)
 Reports a missing, required option.
void ReportMinimumViolation (string arg, decimal? minValue, decimal value)
 Reports a minimum value constraint violation.
void ReportMaximumViolation (string arg, decimal? maxValue, decimal value)
 Reports a minimum value constraint violation.

Protected Member Functions

virtual string[] GenerateHelpHead< T > (ParserOptions parserOptions)
 Generates the help header from attributes or defaults to something legible including the current app file.
virtual string[] GenerateArgumentHelp< T > (CommandlineArgument[] options)
 Generates the help for the arguments section.
virtual string FormatDescriptionText (string description, bool isFlag, object defaultValue, string envVarForDefault, bool isHelpFlag)
 Formats the description text for an argument to make it "fit on the right".
virtual string TypeAnnotationFor (string type, bool isFlag)
 Produces a formatted type annotation for an argument.
string FormatOptionHelp (string shortName, string longName, string type, bool isFlag, string helpText, int leftColWidth, int maxLineWidth)
 Formats the help entry for an option.
string FormatArg (string name, int dashes, bool isFirst)
 Formats the argument part of argument help (eg '-h, –help') Should be called twice per argument, with a flag as to whether it's the first call (for the short part) or the second (for the long part)
virtual string[] GenerateHelpFooter< T > (ParserOptions parserOptions)
 Generates the help footer from a [MoreInfo] attribute.
string[] ReadTextAttributes< THost, TAttribute > ()
 Reads all values from text-based attributes of type TAttribute which decorate THost.

Properties

Action< string > LineWriter = Console.WriteLine [get, set]
 Writes a line to the output (default is Console.WriteLine)
Action< int > ExitAction = Environment.Exit [get, set]
 Used to exit the app when necessary (default Environment.Exit)
bool ExitWhenShowingHelp = true [get, set]
 (flag) exit when showing help? default true
bool ShowedHelp = false [get, set]
 (flag) did we show help? useful if you choose not to exit when showing help
bool ExitOnError = true [get, set]
 (flag) should we exit when args have an error? default true
bool IgnoreUnknownSwitches [get, set]
 (flag) ignore unknown switches - only include them in the collected
bool EnableExtendedParsing = true [get, set]
 When enabled, some condensed versions of argument handling are enabled, including running together short flag arguments, eg -n -a -b => -nab specifying numeric values without spaces, eg -l 1234 => -l1234.
int ConsoleColumns [get, set]
 When unable to determine the number of columns available to the console, fall back on this value.
virtual string NegateMessage [get]
 Message to display about the auto –no-{arg} functionality for flags.
virtual int ConsoleWidth [get]
 Provides the window width for the console (falling back on the value of ConsoleColumns (default: 100) when that fails)
string[] Description [get, set]
 Override any overall help description.
string[] MoreInfo [get, set]
 Provide the help footer via parser argument rather than from the decorated [MoreInfo].
bool IncludeDefaultDescription [get, set]
 When specifying a description for your options, whether or not the default {programname.exe} {args} should be included.
bool ShowHelpOnArgumentError [get, set]
 Automatically show help text on argument error.
bool FallbackOnEnvironmentVariables [get, set]
 When enabled, environment variables will be observed as fallback values for arguments. For example, if you have a RemoteHost property, then any of the following environment variables should configure it if it is not explicitly set from the commandline: REMOTEHOST REMOTE_HOST ReMOteHosT.

Detailed Description

Provides options for the parser.

Member Function Documentation

◆ DisplayHelp< T >()

virtual void PeanutButter.EasyArgs.ParserOptions.DisplayHelp< T > ( CommandlineArgument[] options)
virtual

Displays help via the LineWriter action.

Parameters
options
Template Parameters
T

◆ FormatArg()

string PeanutButter.EasyArgs.ParserOptions.FormatArg ( string name,
int dashes,
bool isFirst )
protected

Formats the argument part of argument help (eg '-h, –help') Should be called twice per argument, with a flag as to whether it's the first call (for the short part) or the second (for the long part)

Parameters
name
dashes
isFirst
Returns

◆ FormatDescriptionText()

virtual string PeanutButter.EasyArgs.ParserOptions.FormatDescriptionText ( string description,
bool isFlag,
object defaultValue,
string envVarForDefault,
bool isHelpFlag )
protectedvirtual

Formats the description text for an argument to make it "fit on the right".

Parameters
description
isFlag
defaultValue
envVarForDefault
isHelpFlag
Returns

◆ FormatOptionHelp()

string PeanutButter.EasyArgs.ParserOptions.FormatOptionHelp ( string shortName,
string longName,
string type,
bool isFlag,
string helpText,
int leftColWidth,
int maxLineWidth )
protected

Formats the help entry for an option.

Parameters
shortName
longName
type
isFlag
helpText
leftColWidth
maxLineWidth
Returns

◆ GenerateArgumentHelp< T >()

virtual string[] PeanutButter.EasyArgs.ParserOptions.GenerateArgumentHelp< T > ( CommandlineArgument[] options)
protectedvirtual

Generates the help for the arguments section.

Parameters
options
Template Parameters
T
Returns

◆ GenerateHelpFooter< T >()

virtual string[] PeanutButter.EasyArgs.ParserOptions.GenerateHelpFooter< T > ( ParserOptions parserOptions)
protectedvirtual

Generates the help footer from a [MoreInfo] attribute.

Parameters
parserOptions
Template Parameters
T
Returns

◆ GenerateHelpHead< T >()

virtual string[] PeanutButter.EasyArgs.ParserOptions.GenerateHelpHead< T > ( ParserOptions parserOptions)
protectedvirtual

Generates the help header from attributes or defaults to something legible including the current app file.

Parameters
parserOptions
Template Parameters
T
Returns

◆ ReadTextAttributes< THost, TAttribute >()

string[] PeanutButter.EasyArgs.ParserOptions.ReadTextAttributes< THost, TAttribute > ( )
protected

Reads all values from text-based attributes of type TAttribute which decorate THost.

Template Parameters
THost
TAttribute
Returns
Type Constraints
TAttribute :StringAttribute 

◆ ReportConflict()

virtual void PeanutButter.EasyArgs.ParserOptions.ReportConflict ( string left,
string right )
virtual

Reports that two conflicting arguments were specified.

Parameters
left
right

◆ ReportMaximumViolation()

void PeanutButter.EasyArgs.ParserOptions.ReportMaximumViolation ( string arg,
decimal? maxValue,
decimal value )

Reports a minimum value constraint violation.

Parameters
arg
maxValue
value
Exceptions
NotImplementedException

◆ ReportMinimumViolation()

void PeanutButter.EasyArgs.ParserOptions.ReportMinimumViolation ( string arg,
decimal? minValue,
decimal value )

Reports a minimum value constraint violation.

Parameters
arg
minValue
value
Exceptions
NotImplementedException

◆ ReportMissingFile()

virtual void PeanutButter.EasyArgs.ParserOptions.ReportMissingFile ( string arg,
string value )
virtual

Reports when an expected file is missing.

Parameters
arg
value

◆ ReportMissingRequiredOption()

virtual void PeanutButter.EasyArgs.ParserOptions.ReportMissingRequiredOption ( CommandlineArgument arg)
virtual

Reports a missing, required option.

Parameters
arg

◆ ReportMultipleValuesForSingleValueArgument()

virtual void PeanutButter.EasyArgs.ParserOptions.ReportMultipleValuesForSingleValueArgument ( string arg)
virtual

Reports that multiple values were found for a single-value argument.

Parameters
arg

◆ ReportUnknownSwitch()

virtual void PeanutButter.EasyArgs.ParserOptions.ReportUnknownSwitch ( string arg)
virtual

Reports that an unknown switch was encountered.

Parameters
arg

◆ TypeAnnotationFor()

virtual string PeanutButter.EasyArgs.ParserOptions.TypeAnnotationFor ( string type,
bool isFlag )
protectedvirtual

Produces a formatted type annotation for an argument.

Parameters
type
isFlag
Returns

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.EasyArgs/ParserOptions.cs