All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Valuable::CmdParser Class Reference

Command line parser. More...

#include <Valuable/CmdParser.hpp>

Public Member Functions

bool isParsed (const QString &name)
 Query the CmdParser if a certain command line parameter has been parsed. More...
 
QStringList parseAndStore (int &argc, char *argv[], Valuable::Node &opts)
 Parses command line arguments to given Node object. More...
 
QStringList parseAndStore (const QStringList &argv, Valuable::Node &opts)
 

Static Public Member Functions

static QStringList parse (int &argc, char *argv[], Valuable::Node &opts)
 Parses command line arguments to given Node object. More...
 
static QStringList parse (const QStringList &argv, Valuable::Node &opts)
 

Detailed Description

Command line parser.

Member Function Documentation

bool Valuable::CmdParser::isParsed ( const QString &  name)

Query the CmdParser if a certain command line parameter has been parsed.

Parameters
nameThe name of the parameter to query

Example:

CmdParser parser;
parser.parseAndStore(argc, argv, opts);
if(parser.isParsed("foo") printf("--foo was parsed\n");
Returns
True if the parameter was parsed.
static QStringList Valuable::CmdParser::parse ( int &  argc,
char *  argv[],
Valuable::Node opts 
)
static

Parses command line arguments to given Node object.

Parameters
argcNumber of arguments in argv
argvArray of arguments
optsThe target object where the Attributes are stored

If there is a Attribute named "foo" in opts, it can be set in command line like this: –foo param where param will be parsed with deserialize().

If the Attribute name is only one letter, then the parser also recognizes the command like argument that begins with one dash, like -o dir

Boolean arguments (AttributeBool objects) don't use distinct parameter, but they will be switched on by –name and off by –no-name.

String lists are separated by semicolon (;) that can be escaped with backslash: –css style1.css;style2.css

Example:

Node opts;
AttributeInt limit(&opts, "limit", 5);
AttributeString target(&opts, "target", "/tmp/target");
AttributeBool verbose(&opts, "v", false);
AttributeBool recursive(&opts, "recursive", true);
StringList files = CmdParser::parse(argc, argv, opts);

Example input: -v –limit 12 –no-recursive –target out file1.txt file2.txt

Returns
List of arguments that didn't match any Attribute in opts.
Examples:
BookExample.cpp.
QStringList Valuable::CmdParser::parseAndStore ( int &  argc,
char *  argv[],
Valuable::Node opts 
)

Parses command line arguments to given Node object.

Parameters
argcNumber of arguments in argv
argvArray of arguments
optsThe target object where the Attributes are stored

This is the non-static version of the parse function. This version stores all parsed command line arguments in an internal set, which can be queried by the is_parsed function.

Returns
List of arguments that didn't match any Attribute in opts.