StauffConsulting.Essentials.| C#: |
public class CmdLineParser :
object
|
| VB: |
Public Class CmdLineParser
Inherits Object
|
| Type Ancestry: | Object |
This class allows you to define the syntax for the command-line arguments
that are passed to a console program when it is launched, and made available
through the argument to the
Main
method.
This class recognizes three fundamental kinds of tokens:
The command-line syntax recognized by this class is as follows:
command_line
|
:= [element [whitespace element]...]
|
element
|
:= non_switch | (switch [arg_list])
|
arg_list
|
:= (whitespace switch_arg)...
|
switch_arg
|
:= token
|
switch
|
:= "-" token
|
non_switch
|
:= token
|
token
|
:=
any sequence of non-space characters, not beginning with "-"
|
whitespace
|
:=
space
|
tab
|
"foobar"
, the parser will
recognize
"-foo"
as matching that switch, as long as there are no
other switches beginning with
"-foo"
.
Switches are not case-sensitive.
CmdLineParser
object.
Switch
class you need
to define your switches. Pass to the constructors whatever default values
you want to use if the corresponding switch doesn't appear in the command line.
CmdLineParser
object using
the
AddSwitch
method.
Parse
method to parse
the command line arguments. If any errors are encountered,
Parse
will throw a
SyntaxError
.
CmdLineParser |
Constructs a command line parser. |
AddSwitch |
Adds a switch to the command parser. |
AddSwitches |
Adds a collection of switches to the command parser. |
DefineHelp |
Defines a help overview message. |
DefineNonSwitch |
Defines where to put non-switch arguments. |
DefineNonSwitch |
|
Parse |
Parses the command line arguments, and places any switch values in the appropriate Switch objects. |
WordWrap |
Word-wraps a string to fit in the given number of columns. |
WriteHelp |
Displays help. |
| C#: |
CmdLineParser ()
|
| VB: |
Sub New()
|
| C#: |
Void AddSwitch(StauffConsulting.Essentials.Switch s)
|
| VB: |
Function AddSwitch(ByVal s As StauffConsulting.Essentials.Switch) As Void
|
Parameters
s |
| C#: |
Void AddSwitches(System.Collections.ICollection c)
|
| VB: |
Function AddSwitches(ByVal c As System.Collections.ICollection) As Void
|
Parameters
c |
| C#: |
Void DefineHelp(string help)
|
| VB: |
Function DefineHelp(ByVal help As String) As Void
|
Parameters
help | the help string. |
| C#: |
Void DefineNonSwitch(string[] values,
string help)
|
| VB: |
Function DefineNonSwitch(ByVal values() As String, ByVal help As String) As Void
|
CmdLineParser
object. If it is called more than once,
an assertion will fail.
Parameters
values |
this array will receive the values of the non-
switch arguments when the command line is parsed.
If the user provides more non-switch arguments
than will fit in this array, the parser will
throw a SyntaxError.
|
help | a help string describing the expected arguments. This will be printed when help is requested. It should not contain any newlines; help output is automatically word-wrapped. |
| C#: |
Void DefineNonSwitch(System.Collections.Generic.List
|
| VB: |
Function DefineNonSwitch(ByVal values As System.Collections.Generic.List(Of String), ByVal help As String) As Void
|
Parameters
values | |
help |
| C#: |
Void Parse(string[] cmdLineArgs)
|
| VB: |
Function Parse(ByVal cmdLineArgs() As String) As Void
|
CmdLineParser
object. If it is called more than once,
an assertion will fail.
Parameters
cmdLineArgs |
the command line arguments that were passed
to Main().
|
| C#: |
static String WordWrap(string input,
int maxColumns,
string prefix)
|
| VB: |
Shared Function WordWrap(ByVal input As String, ByVal maxColumns As Integer, ByVal prefix As String) As [String]
|
Parameters
input | the string to be word-wrapped. |
maxColumns | the maximum number of columns; i.e. the maximum number of characters per line. |
prefix | a string to prepend to the beginning of each line, or null. |
| RETURNS | the word-wrappped string |
| C#: |
Void WriteHelp(System.IO.TextWriter tw,
int helpWidth)
|
| VB: |
Function WriteHelp(ByVal tw As System.IO.TextWriter, ByVal helpWidth As Integer) As Void
|
Parameters
tw | where to write it |
helpWidth | width in characters for wrapping text; 0 = no wrap |