HDK
|
#include <argparse.h>
Public Member Functions | |
Arg (ArgParse &ap) | |
Arg (const Arg &)=delete | |
const Arg & | operator= (const Arg &)=delete |
Arg & | help (string_view help) |
Set the help / description of this command line argument. More... | |
Arg & | nargs (int n) |
Arg & | metavar (string_view name) |
Arg & | dest (string_view dest) |
template<typename T > | |
Arg & | defaultval (const T &val) |
Arg & | hidden () |
Mark the argument as hidden from the help message. More... | |
Arg & | store_true () |
Arg & | store_false () |
Arg & | action (ArgAction &&func) |
Add an arbitrary action: func(Arg&, cspan<const char*>) More... | |
Arg & | action (Action &&func) |
Add an arbitrary action: func(cspan<const char*>) More... | |
Arg & | action (void(*func)()) |
Add an arbitrary action: func() More... | |
Arg & | action (int(*func)(int, const char **)) |
string_view | name () const |
Return the name of the argument. More... | |
string_view | dest () const |
ArgParse & | argparse () |
Get a reference to the ArgParse that owns this Arg. More... | |
Protected Attributes | |
ArgParse & | m_argparse |
A call to ArgParse::arg()
returns an Arg&
. There are lots of things you can do to that reference to modify it. Nearly all Arg methods return an Arg&
so you can chain the calls, like this:
ArgParse ap; ... ap.add_argument("-v") .help("Verbose mode") .action(Arg::store_true());
Definition at line 404 of file argparse.h.
|
inline |
Definition at line 408 of file argparse.h.
|
delete |
Add an arbitrary action: func(Arg&, cspan<const char*>)
Add an arbitrary action: func(cspan<const char*>)
Definition at line 513 of file argparse.h.
Add an arbitrary action: func()
Definition at line 528 of file argparse.h.
Definition at line 534 of file argparse.h.
|
inline |
Get a reference to the ArgParse that owns this Arg.
Definition at line 549 of file argparse.h.
Initialize the destination attribute with a default value. Do not call .dest("name")
on the argument after calling defaultval, of it will end up with the default value in the wrong attribute.
Definition at line 478 of file argparse.h.
Arg& ArgParse::Arg::dest | ( | string_view | dest | ) |
Override the destination attribute name (versus the default which is simply the name of the command line option with the leading dashes stripped away). The main use case is if you want two differently named command line options to both store values into the same attribute. It is very important that if you use dest(), you call it before setting the action.
Example:
// Add -v argument, but store its result in `ap["verbose"]` // rather than the default `ap["v"]`. ap.add_argument("-v") .help("verbose mode") .dest("verbose") .action(ArgParse::store_true());
string_view ArgParse::Arg::dest | ( | ) | const |
Return the "destination", the name of the attribute in which the argument value will be stored.
Arg& ArgParse::Arg::help | ( | string_view | help | ) |
Set the help / description of this command line argument.
Arg& ArgParse::Arg::hidden | ( | ) |
Mark the argument as hidden from the help message.
Arg& ArgParse::Arg::metavar | ( | string_view | name | ) |
Set the name(s) of any argument parameters as they are printed in the help message. For arguments that take multiple parameters, just put spaces between them. Note that the number of arguments is inferred by the number of metavar names, so there is no need to set nargs separately if metavar() is called properly.
Examples:
ArgParse ap; ap.add_argument("--aa") .help("set sampling rate (per pixel)") .metavar("SAMPLES"); ap.add_argument("--color") .help("set the diffuse color") .metavar("R G B");
Will print help like:
--aa SAMPLES set sampling rate (per pixel) --color R G B set the diffuse color
string_view ArgParse::Arg::name | ( | ) | const |
Return the name of the argument.
Set the number of subsequent parameters to this argument. Setting nargs(0)
means it is a flag only, with no parameters.
|
inline |
Set the action for this argument to store 0 in the destination attribute. Initialize the destination attribute to 1 now. Do not call .dest("name")
on the argument after calling store_false, you must override the destination first!
Definition at line 502 of file argparse.h.
|
inline |
Set the action for this argument to store 1 in the destination attribute. Initialize the destination attribute to 0 now. Do not call .dest("name")
on the argument after calling store_true, you must override the destination first!
Definition at line 491 of file argparse.h.
|
protected |
Definition at line 552 of file argparse.h.