HDK
|
#include <argparse.h>
Classes | |
class | Arg |
Public Types | |
using | Action = std::function< void(cspan< const char * > myargs)> |
Holder for a callback that takes a span of C strings as arguments. More... | |
using | ArgAction = std::function< void(Arg &arg, cspan< const char * > myargs)> |
typedef std::function< void(const ArgParse &ap, std::ostream &)> | callback_t |
Static Public Member Functions | |
static ArgAction | store_true () |
Return an action that stores 1 into its destination attribute. More... | |
static ArgAction | store_false () |
Return an action that stores 0 into its destination attribute. More... | |
template<typename T > | |
static ArgAction | store_const (const T &value) |
static ArgAction | store_const (const char *value) |
template<typename T = ustring> | |
static ArgAction | store () |
template<typename T = ustring> | |
static ArgAction | append () |
static Action | do_nothing () |
Friends | |
class | ArgOption |
Argument Parsing. Kind of resembles Python argparse library.
Set up argument parser:
ArgParse ap; ap.intro("myapp does good things") .usage("myapp [options] filename..."); ap.arg("filename") .hidden() .action([&](cspan<const char*> argv){ filenames.emplace_back(argv[0]); });
Declare arguments. Some examples of common idioms:
// Boolean option (no arguments) ap.arg("-v") .help("verbose mode") .action(ArgParse::store_true()); // integer option ap.arg("-passes NPASSES") .help("number of passes") .defaultval(1) .action(ArgParse::store<int>); // An option that takes 3 float arguments, like a V3f ap.arg("-camera X Y Z") .help("set the camera position") .defaultval(Imath::V3f(0.0f, 0.0f, -1.0f)) .action(ArgParse::store<float>()); // Positional argument -- append strings ap.arg("filename") .action(ArgParse::append()) .hidden();
Parse the command line:
ap.parse (argc, argv);
Extract the values like they are attributes in a ParamValueList:
int passes = ap["passes"].get<int>(); bool verbose = ap["verbose"].get<int>(); Imath::V3f camera = ap["camera"].get<Imath::V3f>();
Definition at line 174 of file argparse.h.
typedef std::function<void(const ArgParse& ap, std::ostream&)> ArgParse::callback_t |
Definition at line 751 of file argparse.h.
Definition at line 748 of file argparse.h.
void ArgParse::set_postoption_help | ( | callback_t | callback | ) |
void ArgParse::set_preoption_help | ( | callback_t | callback | ) |
|
inline |
Definition at line 758 of file argparse.h.
|
friend |
Definition at line 731 of file argparse.h.