parse_args library

A package with a simple API for command-line arguments parsing

Classes

CliOpt
Class representing actual command-line option with arguments retrieved from the parsed arguments
CliOptDef
Class representing an option definition (parsed from an options definition string)
CliOptParser
Class to parse command-line arguments as options and their values
CliSubCmdParser
Class to break command-line arguments into a sub-command and its arguments
GlobOpt
Helper class to accumulate Glob options then to pass those as a user-defined parameter (a single object) to the method like CliOptList.toGlobValue(...)
RegExpOpt
Helper class to accumulate RegExp options then to pass those as a user-defined parameter (a single object) to the method like CliOptList.toRegExpValue(...)

Enums

CliOptCaseMode
The way to compare and find option and sub-option names
CliOptStopMode
The way to stop treating arguments as option names

Extensions

CliOptDefList on List<CliOptDef>
Extension methods to manipulate option definitions lists
CliOptList on List<CliOpt>
Extension methods to manipulate command-line arguments. Returns true if more values can be added, or false otherwise.
CliOptName on String
Extension to String for command-line option name manipulations
ListEx on List
Extension methods to manipulate generic lists

Functions

parseArgs(String optDefStr, List<String> args, {CliOptCaseMode caseMode = CliOptCaseMode.smart, bool validate = false}) List<CliOpt>
Loops through all command-line arguments args, determines options, collects possible values, validates those against optDefStr and returns a list of parsed options for the further queries by using isSet(...), getStrValues(...) etc.
parseSubCmd(List<String> args, {CliOptSubCmdMap? map}) bool
Parse sub-commands and their arguments

Typedefs

CliOptSubCmdMap = Map<String, dynamic Function(List<String> args)>
Shorthand for a sub-commands map
CliOptValueConverter = dynamic Function(CliOptDef optDef, String value, {dynamic param})
Single value custom converter

Exceptions / Errors

CliOptBadSubNameException
When encountered a sub-option name containing invalid characters
CliOptException
Base exception class for command-line options parsing
CliOptLongNameAsBundleException
When encountered a long option name consisting of some short option names only (might happen only if smart bundling is turned on)
CliOptUndefinedNameException
When encountered an unrecognised option
CliOptValueMissingException
When encountered an option with no value
CliOptValueTooManyException
When encountered an option with more than one value when only one expected
CliOptValueTypeException
When failed either to recognise the verb or to parse the string value
CliOptValueUnexpectedException
When encountered an option with value(s) instead of a flag
CliSubOptMismatchException
When encountered an unrecognised option