class GeneralArgsParser
Defined at line 43 of file ../../zircon/system/ulib/cmdline/include/lib/cmdline/args_parser.h
A command line arguments parser.
Background: The fxl::CommandLine class is designed to be either a global or
passed around, and code can query it for random switch strings as it feels
necessary. In the fxl::CommandLine model, the set of command-line switches
isn't known in advance. This means that it can't generate help or validate
the switches. It also can't support switches with values that don't use an
equal sign ("-c foo") because it can't disambiguate whether "foo" is a value
for the "-c" switch or a standalone parameter. fxl::CommandLine also
supports modification and generation of new command lines.
In contrast, this command-line parser requires registration of all switches
in advance. It can then validate inputs, generate help, and accept more
flexible value formatting. This class is designed exclusively as a parser
which makes it simpler.
The command line args parser has two layers. The lower "general" layer is a
concrete class that parses the command line and calls callbacks for
switches that have been registered.
On top of this is the ArgsParser which is a template that fills
a struct with registered options. This is what most code will want, but
you can still register custom callbacks for more complex behavior.
Public Methods
void GeneralArgsParser ()
Defined at line 51 of file ../../zircon/system/ulib/cmdline/args_parser.cc
void ~GeneralArgsParser ()
Defined at line 52 of file ../../zircon/system/ulib/cmdline/args_parser.cc
void AddGeneralSwitch (const char * long_name, const char short_name, const char * help, OnOffSwitchCallback on_switch, OnOffSwitchCallback off_switch)
The parameter type (or whether there is a parameter at all) is controlled
by the type of callback passed to the AddGeneralSwitch command.
If there is no short name, pass a zero for the character.
The callback will be called if the switch is specified. With passed-in
strings must outlive this class (they're assumed to be static).
Defined at line 54 of file ../../zircon/system/ulib/cmdline/args_parser.cc
void GeneralArgsParser (const GeneralArgsParser & )
disallow copy and assign
Defined at line 61 of file ../../zircon/system/ulib/cmdline/include/lib/cmdline/args_parser.h
GeneralArgsParser & operator= (const GeneralArgsParser & )
Defined at line 62 of file ../../zircon/system/ulib/cmdline/include/lib/cmdline/args_parser.h
void AddGeneralSwitch (const char * long_name, const char short_name, const char * help, StringCallback )
Defined at line 67 of file ../../zircon/system/ulib/cmdline/args_parser.cc
std::string GetHelp ()
Constructs a help reference for all switches based on the help strings
passed to AddGeneralSwitch().
Defined at line 76 of file ../../zircon/system/ulib/cmdline/args_parser.cc
Status ParseGeneral (int argc, const char *const[] argv, std::vector<std::string> * params)
Parses the given command line. The callbacks are called for any provided
switches, and any non-switch values are placed into the given output
vector.
Defined at line 91 of file ../../zircon/system/ulib/cmdline/args_parser.cc