#include <SimpleCLParser.h>
Public Methods | |
template<class AC> void | add (const QString &flag, AC &val, const QString &descr, bool required=false) |
Adds a command-line flag to the list of arguments which will be looked for. | |
template<class AC> void | addPositional (const QString &flag, AC &val, const QString &descr, bool required=false) |
Adds a positional command-line argument to the list of arguments which will be looked for. | |
void | parse (int argc, char **argv) |
Parses the given arguments and puts their values into the variables passed to add(). | |
void | usage (const QString &msg=QString()) |
Prints a formatted usage message to cerr and terminates the program. | |
void | dispose () |
Cleans up the storage allocated by calls to add(). |
This one takes references to the variables which you want to fill from the command line, and
For example, if you take an input file & output file, some integer, and a boolean flag, you might declare these variables:
QString infile("foo.in"), outfile("foo.out"); int its = 10; bool hose = false;
and register the arguments (and their descriptions) like this:
OtherSimpleCLParser args; args.add("i filename", infile, "the input file"); args.add("o filename", outfile, "the output file"); args.add("it iterations", its, "number of times to iterate"); args.add("h", hose, "hose things up"); ... args.parse(argc, argv);
If there were errors, a usage message was generated & printed, and the program was terminated. You can do additional checking afterwards:
if (infile == outfile) args.usage("infile == outfile, you bozo");
When you're all done checking the command line arguments, let the OtherSimpleCLParser object go out of scope, or call its dispose() method. (The variables you gave it will continue to contain the values which were passed on the command line, of course.)
Definition at line 134 of file SimpleCLParser.h.
|
Adds a command-line flag to the list of arguments which will be looked for.
Definition at line 247 of file SimpleCLParser.h. |
|
Adds a positional command-line argument to the list of arguments which will be looked for. Note that all required positional arguments must precede optional positional arguments. Also, a positional argument type which takes multiple arguments (like QStringList) will cause everything after it to never be received, because all the arguments will go into the QStringList. (OK, rereading that, it doesn't even make sense to me. Sorry!)
Definition at line 254 of file SimpleCLParser.h. |
|
Cleans up the storage allocated by calls to add(). Call this when you're done using the OtherSimpleCLParser (that is, after the last point when you'd call usage()), or just let it go out of scope. Definition at line 417 of file SimpleCLParser.cpp. |
|
Parses the given arguments and puts their values into the variables passed to add(). If there are errors, usage() is called. Definition at line 207 of file SimpleCLParser.cpp. References usage(). |
|
Prints a formatted usage message to cerr and terminates the program. If a specific message is supplied, it's printed first. Definition at line 326 of file SimpleCLParser.cpp. Referenced by parse(). |