|
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 |
Public Member Functions | |
| ArgParse () | |
| Construct an ArgParse. More... | |
| ~ArgParse () | |
| Destroy an ArgParse. More... | |
| ArgParse (int argc, const char **argv) | |
| ArgParse (const ArgParse &)=delete | |
| const ArgParse & | operator= (const ArgParse &)=delete |
| ArgParse (ArgParse &&other) | |
| Move constructor. More... | |
| ArgParse & | intro (string_view str) |
| ArgParse & | usage (string_view str) |
| ArgParse & | description (string_view str) |
| ArgParse & | epilog (string_view str) |
| ArgParse & | prog (string_view str) |
| ArgParse & | print_defaults (bool print) |
| ArgParse & | add_help (bool add_help) |
| ArgParse & | add_version (string_view version_string) |
| ArgParse & | exit_on_error (bool exit_on_error) |
| void | abort (bool aborted=true) |
| bool | aborted () const |
| Reveal whether the current state is aborted. More... | |
| void | running (bool run) |
| Set whether current actions should run. More... | |
| bool | running () const |
| Reveal whether current actions should run. More... | |
| int | current_arg () const |
| Reveal the current argument that is being parsed. More... | |
| void | set_next_arg (int nextarg) |
| Set the next argument to be processed. Use with extreme caution! More... | |
| int | parse_args (int argc, const char **argv) |
| bool | has_error () const |
| Is there a pending error message waiting to be retrieved? More... | |
| std::string | geterror (bool clear=true) const |
| std::string | prog_name () const |
| void | print_help () const |
| void | briefusage () const |
| std::string | command_line () const |
| Return the entire command-line as one string. More... | |
| Arg & | add_argument (const char *argname) |
| template<typename... T> | |
| Arg & | add_argument (const char *argname, T...args) |
| Arg & | arg (const char *argname) |
| Shorter synonym for add_argument(). More... | |
| template<typename... T> | |
| Arg & | arg (const char *argname, T...args) |
| Shorter synonym for add_argument(). More... | |
| Arg & | separator (string_view text) |
| AttrDelegate< const ParamValueList > | operator[] (string_view name) const |
| Access a single argument result by name. More... | |
| AttrDelegate< ParamValueList > | operator[] (string_view name) |
| Access a single argument result by name. More... | |
| ParamValueList & | params () |
| Directly access the ParamValueList that holds the argument results. More... | |
| const ParamValueList & | cparams () const |
| int | options (const char *intro,...) |
| int | parse (int argc, const char **argv) |
| void | set_preoption_help (callback_t callback) |
| void | set_postoption_help (callback_t callback) |
| void | usage () const |
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 770 of file argparse.h.
| int ArgParse::options | ( | const char * | intro, |
| ... | |||
| ) |
Definition at line 767 of file argparse.h.
| void ArgParse::set_postoption_help | ( | callback_t | callback | ) |
| void ArgParse::set_preoption_help | ( | callback_t | callback | ) |
|
inline |
Definition at line 777 of file argparse.h.
|
friend |
Definition at line 750 of file argparse.h.