Table of Contents

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

IEnumerable<CmdlineParseItem>

AllItems

parent and this items

public IEnumerable<CmdlineParseItem> AllItems { get; }

Property Value

IEnumerable<CmdlineParseItem>

AppVersion

app version utility

public string AppVersion { get; }

Property Value

string

Colors

colors set ( this can be changed from the Create method )

public CmdlineColors Colors { get; }

Property Value

CmdlineColors

Command

command that activate this parser

public CmdlineParseItem Command { get; }

Property Value

CmdlineParseItem

Commands

this parser commands

public IEnumerable<CmdlineParseItem> Commands { get; }

Property Value

IEnumerable<CmdlineParseItem>

Description

description of this parser ( automatically retrieved from command if this is a subparser )

public string Description { get; }

Property Value

string

Flags

this parser flags

public IEnumerable<CmdlineParseItem> Flags { get; }

Property Value

IEnumerable<CmdlineParseItem>

FriendlyName

assembly friendly name ( used for Usage )

public string FriendlyName { get; }

Property Value

string

GlobalFlags

global flags

public IEnumerable<CmdlineParseItem> GlobalFlags { get; }

Property Value

IEnumerable<CmdlineParseItem>

InheritedFlags

only parent parsers flags

public IEnumerable<CmdlineParseItem> InheritedFlags { get; }

Property Value

IEnumerable<CmdlineParseItem>

InheritedItems

only parents items

public IEnumerable<CmdlineParseItem> InheritedItems { get; }

Property Value

IEnumerable<CmdlineParseItem>

Items

this (sub)parser items

public IReadOnlyList<CmdlineParseItem> Items { get; }

Property Value

IReadOnlyList<CmdlineParseItem>

ParameterArrays

parameter with array mode

public IEnumerable<CmdlineParseItem> ParameterArrays { get; }

Property Value

IEnumerable<CmdlineParseItem>

Parameters

parameters

public IEnumerable<CmdlineParseItem> Parameters { get; }

Property Value

IEnumerable<CmdlineParseItem>

ParametersOrArray

all parameters single or array mode

public IEnumerable<CmdlineParseItem> ParametersOrArray { get; }

Property Value

IEnumerable<CmdlineParseItem>

Parent

parent parset ( null for topmost parser )

public CmdlineParser Parent { get; }

Property Value

CmdlineParser

ParentParsers

parent parsers enum

public IEnumerable<CmdlineParser> ParentParsers { get; }

Property Value

IEnumerable<CmdlineParser>

ParserPath

list of parser from topmost to this one

public IEnumerable<CmdlineParser> ParserPath { get; }

Property Value

IEnumerable<CmdlineParser>

RootParser

topmost parser

public CmdlineParser RootParser { get; }

Property Value

CmdlineParser

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 string

name of the command

description string

description of the command ( for the usage )

builder Action<CmdlineParser>

an optional builder to create a subparser from this command

Returns

CmdlineParseItem

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 string
description string
valueName string
globalFlagAction Action<CmdlineParseItem>
globalFlagActionNested bool

Returns

CmdlineParseItem

AddMandatoryLong(string, string, string)

add mandatory long flag

public CmdlineParseItem AddMandatoryLong(string name, string description, string valueName = null)

Parameters

name string
description string
valueName string

Returns

CmdlineParseItem

AddMandatoryParameter(string, string)

add mandatory parameter item to this parser

public CmdlineParseItem AddMandatoryParameter(string name, string description)

Parameters

name string

name of this parameter ( used in Usage )

description string

description of this parameter ( used in Usage )

Returns

CmdlineParseItem

AddMandatoryParameterArray(string, string)

add mandatory parameter array item to this parser

public CmdlineParseItem AddMandatoryParameterArray(string name, string description)

Parameters

name string

name of this parameter array ( used in Usage )

description string

description of this parameter array ( used in Usage )

Returns

CmdlineParseItem

AddMandatoryShort(string, string, string)

add mandatory short flag

public CmdlineParseItem AddMandatoryShort(string name, string description, string valueName = null)

Parameters

name string
description string
valueName string

Returns

CmdlineParseItem

AddMandatoryShortLong(string, string, string, string)

add mandatory short/long flag

public CmdlineParseItem AddMandatoryShortLong(string shortName, string longName, string description, string valueName = null)

Parameters

shortName string
longName string
description string
valueName string

Returns

CmdlineParseItem

AddParameter(string, string)

add optional parameter item to this parser

public CmdlineParseItem AddParameter(string name, string description)

Parameters

name string

name of this parameter ( used in Usage )

description string

description of this parameter ( used in Usage )

Returns

CmdlineParseItem

AddParameterArray(string, string)

add optional parameter array item to this parser

public CmdlineParseItem AddParameterArray(string name, string description)

Parameters

name string

name of this parameter array ( used in Usage )

description string

description of this parameter array ( used in Usage )

Returns

CmdlineParseItem

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 string
description string
valueName string
globalFlagAction Action<CmdlineParseItem>
globalFlagActionNested bool

Returns

CmdlineParseItem

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 string
longName string
description string
valueName string
globalFlagAction Action<CmdlineParseItem>
globalFlagActionNested bool

Returns

CmdlineParseItem

Create(string, Action<CmdlineParser>, CmdlineColors, bool)

create main parser

public static CmdlineParser Create(string description, Action<CmdlineParser> builder, CmdlineColors colors, bool unescapeArguments)

Parameters

description string

program description

builder Action<CmdlineParser>

action to configure and run the parser

colors CmdlineColors

custom color object or null to disable

unescapeArguments bool

true to unescape arguments ( eg. newlines in argument strings )

Returns

CmdlineParser

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 string

program description

builder Action<CmdlineParser>

action to configure and run the parser

useColors bool

true to use colors

unescapeArguments bool

true to unescape arguments ( eg. newlines in argument strings )

Returns

CmdlineParser

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()

Returns

string