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

Provides the extension methods to parse commandline arguments. More...

Static Public Member Functions

static T ParseTo< T > (this string[] arguments)
 Simplest use-case: parse to provided type, ignoring extraneous command-line argument values; will, however, error on unknown switches.
static T ParseTo< T > (this string[] arguments, ParserOptions options)
 Parse to the provided target type T with provided parser options Unrecognised commandline arguments will be discarded, however, depending on the provided options, the process may exit, printing and error.
static T ParseTo< T > (this string[] arguments, out string[] uncollected)
 Parse to provided type and output all uncollected arguments. Useful if your app, for example, has some switched arguments and then accepts, eg, a collection of file paths.
static T ParseTo< T > (this string[] arguments, out string[] uncollected, ParserOptions options)
 Full-control parsing:
static void PrintHelpFor< T > (ParserOptions options)
 Manually print the help for the provided parse target and options.
static string[] GenerateArgs (this object obj)
 Generates arguments from the options object, preferring long names over short ones.
static string[] GenerateArgs (this object obj, bool preferLongNames)
 Generates arguments from the options object, selecting a preference for long or short names as per preferLongNames.
static string[] GenerateLongArgs (this object obj)
 Generates an args array from the properties of the incoming object, preferring long names for options over short names.
static string[] GenerateShortArgs (this object obj)
 Generates an args array from the properties of the incoming object, preferring short names for options over long names.
static string GenerateCommandline (this object obj)
 Generates the commandline arguments that would re-constitute this options object.

Detailed Description

Provides the extension methods to parse commandline arguments.

Member Function Documentation

◆ GenerateArgs() [1/2]

string[] PeanutButter.EasyArgs.ParserExtensions.GenerateArgs ( this object obj)
static

Generates arguments from the options object, preferring long names over short ones.

Parameters
obj
Returns

◆ GenerateArgs() [2/2]

string[] PeanutButter.EasyArgs.ParserExtensions.GenerateArgs ( this object obj,
bool preferLongNames )
static

Generates arguments from the options object, selecting a preference for long or short names as per preferLongNames.

Parameters
obj
preferLongNames
Returns

◆ GenerateCommandline()

string PeanutButter.EasyArgs.ParserExtensions.GenerateCommandline ( this object obj)
static

Generates the commandline arguments that would re-constitute this options object.

Parameters
obj
Returns

◆ GenerateLongArgs()

string[] PeanutButter.EasyArgs.ParserExtensions.GenerateLongArgs ( this object obj)
static

Generates an args array from the properties of the incoming object, preferring long names for options over short names.

Parameters
obj
Returns

◆ GenerateShortArgs()

string[] PeanutButter.EasyArgs.ParserExtensions.GenerateShortArgs ( this object obj)
static

Generates an args array from the properties of the incoming object, preferring short names for options over long names.

Parameters
obj
Returns

◆ ParseTo< T >() [1/4]

T PeanutButter.EasyArgs.ParserExtensions.ParseTo< T > ( this string[] arguments)
static

Simplest use-case: parse to provided type, ignoring extraneous command-line argument values; will, however, error on unknown switches.

Parameters
arguments
Template Parameters
T
Returns

◆ ParseTo< T >() [2/4]

T PeanutButter.EasyArgs.ParserExtensions.ParseTo< T > ( this string[] arguments,
out string[] uncollected )
static

Parse to provided type and output all uncollected arguments. Useful if your app, for example, has some switched arguments and then accepts, eg, a collection of file paths.

Parameters
arguments
uncollected
Template Parameters
T
Returns

◆ ParseTo< T >() [3/4]

T PeanutButter.EasyArgs.ParserExtensions.ParseTo< T > ( this string[] arguments,
out string[] uncollected,
ParserOptions options )
static

Full-control parsing:

  • collect stray arguments
  • override behavior
    • LineWriter (default is Console.WriteLine)
    • ExitOnError (default is true)
    • ExitAction (default is Environment.Exit)
    • ExitWhenShowingHelp (default is true)
    • Message formatting (make your own messages for the following)
      • ReportMultipleValuesForSingleValueArgument
      • ReportConflict
      • ReportUnknownArg
      • ReportMissingRequiredOption
      • NegateMessage
      • DisplayHelp
        • GenerateHelpHead
        • GenerateArgumentHelp
          • FormatOptionHelp
            • FormatArg
            • TypeAnnotationFor
          • ConsoleWidth
        • GenerateFooter
Parameters
arguments
uncollected
options
Template Parameters
T
Returns

◆ ParseTo< T >() [4/4]

T PeanutButter.EasyArgs.ParserExtensions.ParseTo< T > ( this string[] arguments,
ParserOptions options )
static

Parse to the provided target type T with provided parser options Unrecognised commandline arguments will be discarded, however, depending on the provided options, the process may exit, printing and error.

Parameters
arguments
options
Template Parameters
T
Returns

◆ PrintHelpFor< T >()

void PeanutButter.EasyArgs.ParserExtensions.PrintHelpFor< T > ( ParserOptions options)
static

Manually print the help for the provided parse target and options.

Parameters
options
Template Parameters
T

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