ArgParser class

A class for taking a list of raw command line arguments and parsing out options and flags from them.

Available extensions

Constructors

ArgParser({bool allowTrailingOptions = true, int? usageLineLength})
Creates a new ArgParser.
factory
ArgParser.allowAnything()
Creates a new ArgParser that treats all input as non-option arguments.
factory

Properties

allowsAnything bool
Whether or not this parser treats unrecognized options as non-option arguments.
no setter
allowTrailingOptions bool
Whether or not this parser parses options that appear after non-option arguments.
final
commands Map<String, ArgParser>
The commands that have been defined for this parser.
final
hashCode int
The hash code for this object.
no setterinherited
options Map<String, Option>
The options that have been defined for this parser.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
usage String
Generates a string displaying usage information for the defined options.
no setter
usageLineLength int?
An optional maximum line length for usage messages.
final

Methods

addCommand(String name, [ArgParser? parser]) ArgParser
Defines a command.
addFlag(String name, {String? abbr, String? help, bool? defaultsTo = false, bool negatable = true, void callback(bool)?, bool hide = false, List<String> aliases = const []}) → void
Defines a boolean flag.
addMultiOption(String name, {String? abbr, String? help, String? valueHelp, Iterable<String>? allowed, Map<String, String>? allowedHelp, Iterable<String>? defaultsTo, void callback(List<String>)?, bool splitCommas = true, bool hide = false, List<String> aliases = const []}) → void
Defines an option that takes multiple values.
addOption(String name, {String? abbr, String? help, String? valueHelp, Iterable<String>? allowed, Map<String, String>? allowedHelp, String? defaultsTo, void callback(String?)?, bool mandatory = false, bool hide = false, List<String> aliases = const []}) → void
Defines an option that takes a value.
addSeparator(String text) → void
Adds a separator line to the usage.
defaultFor(String option) → dynamic
Returns the default value for option.
findByAbbreviation(String abbr) Option?
Finds the option whose abbreviation is abbr, or null if no option has that abbreviation.
findByNameOrAlias(String name) Option?
Finds the option whose name or alias matches name, or null if no option has that name or alias.
getDefault(String option) → dynamic
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parse(Iterable<String> args) ArgResults
Parses args, a list of command-line arguments, matches them against the flags and options defined by this parser, and returns the result.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited