Class CmdlineParser
- Namespace
- SearchAThing.Cmdline
- Assembly
- netcore-cmdline.dll
cmdline parser tool
public class CmdlineParser
- Inheritance
-
CmdlineParser
- Inherited Members
Properties
AllFlags
inherited and this parser flags
public IEnumerable<CmdlineParseItem> AllFlags { get; }
Property Value
AllItems
parent and this items
public IEnumerable<CmdlineParseItem> AllItems { get; }
Property Value
AppVersion
app version utility
public string AppVersion { get; }
Property Value
Colors
colors set ( this can be changed from the Create method )
public CmdlineColors Colors { get; }
Property Value
Command
command that activate this parser
public CmdlineParseItem Command { get; }
Property Value
Commands
this parser commands
public IEnumerable<CmdlineParseItem> Commands { get; }
Property Value
Description
description of this parser ( automatically retrieved from command if this is a subparser )
public string Description { get; }
Property Value
Flags
this parser flags
public IEnumerable<CmdlineParseItem> Flags { get; }
Property Value
FriendlyName
assembly friendly name ( used for Usage )
public string FriendlyName { get; }
Property Value
GlobalFlags
global flags
public IEnumerable<CmdlineParseItem> GlobalFlags { get; }
Property Value
InheritedFlags
only parent parsers flags
public IEnumerable<CmdlineParseItem> InheritedFlags { get; }
Property Value
InheritedItems
only parents items
public IEnumerable<CmdlineParseItem> InheritedItems { get; }
Property Value
Items
this (sub)parser items
public IReadOnlyList<CmdlineParseItem> Items { get; }
Property Value
ParameterArrays
parameter with array mode
public IEnumerable<CmdlineParseItem> ParameterArrays { get; }
Property Value
Parameters
parameters
public IEnumerable<CmdlineParseItem> Parameters { get; }
Property Value
ParametersOrArray
all parameters single or array mode
public IEnumerable<CmdlineParseItem> ParametersOrArray { get; }
Property Value
Parent
parent parset ( null for topmost parser )
public CmdlineParser Parent { get; }
Property Value
ParentParsers
parent parsers enum
public IEnumerable<CmdlineParser> ParentParsers { get; }
Property Value
ParserPath
list of parser from topmost to this one
public IEnumerable<CmdlineParser> ParserPath { get; }
Property Value
RootParser
topmost parser
public CmdlineParser RootParser { get; }
Property Value
Methods
AddCommand(string, string, Action<CmdlineParser>)
add a command item to this parser
public CmdlineParseItem AddCommand(string name, string description, Action<CmdlineParser> builder = null)
Parameters
name
stringname of the command
description
stringdescription of the command ( for the usage )
builder
Action<CmdlineParser>an optional builder to create a subparser from this command
Returns
AddLong(string, string, string, Action<CmdlineParseItem>, bool)
add optional long flag
public CmdlineParseItem AddLong(string name, string description, string valueName = null, Action<CmdlineParseItem> globalFlagAction = null, bool globalFlagActionNested = true)
Parameters
name
stringdescription
stringvalueName
stringglobalFlagAction
Action<CmdlineParseItem>globalFlagActionNested
bool
Returns
AddMandatoryLong(string, string, string)
add mandatory long flag
public CmdlineParseItem AddMandatoryLong(string name, string description, string valueName = null)
Parameters
Returns
AddMandatoryParameter(string, string)
add mandatory parameter item to this parser
public CmdlineParseItem AddMandatoryParameter(string name, string description)
Parameters
name
stringname of this parameter ( used in Usage )
description
stringdescription of this parameter ( used in Usage )
Returns
AddMandatoryParameterArray(string, string)
add mandatory parameter array item to this parser
public CmdlineParseItem AddMandatoryParameterArray(string name, string description)
Parameters
name
stringname of this parameter array ( used in Usage )
description
stringdescription of this parameter array ( used in Usage )
Returns
AddMandatoryShort(string, string, string)
add mandatory short flag
public CmdlineParseItem AddMandatoryShort(string name, string description, string valueName = null)
Parameters
Returns
AddMandatoryShortLong(string, string, string, string)
add mandatory short/long flag
public CmdlineParseItem AddMandatoryShortLong(string shortName, string longName, string description, string valueName = null)
Parameters
Returns
AddParameter(string, string)
add optional parameter item to this parser
public CmdlineParseItem AddParameter(string name, string description)
Parameters
name
stringname of this parameter ( used in Usage )
description
stringdescription of this parameter ( used in Usage )
Returns
AddParameterArray(string, string)
add optional parameter array item to this parser
public CmdlineParseItem AddParameterArray(string name, string description)
Parameters
name
stringname of this parameter array ( used in Usage )
description
stringdescription of this parameter array ( used in Usage )
Returns
AddShort(string, string, string, Action<CmdlineParseItem>, bool)
add optional short flag
public CmdlineParseItem AddShort(string name, string description, string valueName = null, Action<CmdlineParseItem> globalFlagAction = null, bool globalFlagActionNested = true)
Parameters
name
stringdescription
stringvalueName
stringglobalFlagAction
Action<CmdlineParseItem>globalFlagActionNested
bool
Returns
AddShortLong(string, string, string, string, Action<CmdlineParseItem>, bool)
add optional short/long flag
public CmdlineParseItem AddShortLong(string shortName, string longName, string description, string valueName = null, Action<CmdlineParseItem> globalFlagAction = null, bool globalFlagActionNested = true)
Parameters
shortName
stringlongName
stringdescription
stringvalueName
stringglobalFlagAction
Action<CmdlineParseItem>globalFlagActionNested
bool
Returns
Create(string, Action<CmdlineParser>, CmdlineColors, bool)
create main parser
public static CmdlineParser Create(string description, Action<CmdlineParser> builder, CmdlineColors colors, bool unescapeArguments)
Parameters
description
stringprogram description
builder
Action<CmdlineParser>action to configure and run the parser
colors
CmdlineColorscustom color object or null to disable
unescapeArguments
booltrue to unescape arguments ( eg. newlines in argument strings )
Returns
Create(string, Action<CmdlineParser>, bool, bool)
create main parser
public static CmdlineParser Create(string description, Action<CmdlineParser> builder, bool useColors = true, bool unescapeArguments = false)
Parameters
description
stringprogram description
builder
Action<CmdlineParser>action to configure and run the parser
useColors
booltrue to use colors
unescapeArguments
booltrue to unescape arguments ( eg. newlines in argument strings )
Returns
OnCmdlineMatch(Action)
set action to execute when this parser cmdline matches
public void OnCmdlineMatch(Action action)
Parameters
action
Action
PrintUsage()
print the usage based on current parser configuration
public void PrintUsage()
Run(string[])
execute the parser ( must called once from top parser builder )
public void Run(string[] args)
Parameters
args
string[]
ToString()
build a table with all parser item details, matches and parsed values ( for debug purpose )
public override string ToString()