PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | List of all members
PICLI Class Reference

Command-Line parser. More...

#include <picli.h>

Public Member Functions

 PICLI (int argc, char *argv[])
 Constructs PICLI from "argc" and "argv" from "int main()" method.
 
void addArgument (const PIString &name, bool value=false)
 Add argument with name "name", short key = name first letter and full key = name.
 
void addArgument (const PIString &name, const PIChar &shortKey, bool value=false)
 Add argument with name "name", short key = "shortKey" and full key = name.
 
void addArgument (const PIString &name, const char *shortKey, bool value=false)
 Add argument with name "name", short key = "shortKey" and full key = name.
 
void addArgument (const PIString &name, const PIChar &shortKey, const PIString &fullKey, bool value=false)
 Add argument with name "name", short key = "shortKey" and full key = "fullKey".
 
void addArgument (const PIString &name, const char *shortKey, const PIString &fullKey, bool value=false)
 Add argument with name "name", short key = "shortKey" and full key = "fullKey".
 
PIString rawArgument (int index)
 Returns unparsed command-line argument by index "index". Index 0 is program execute command.
 
const PIStringListrawArguments ()
 Returns unparsed command-line arguments.
 
PIString programCommand ()
 Returns program execute command without arguments.
 
bool hasArgument (const PIString &name)
 Returns if argument "name" found.
 
PIString argumentValue (const PIString &name)
 Returns argument "name" value, or empty string if this is no value.
 
PIString argumentShortKey (const PIString &name)
 Returns short key of argument "name", or empty string if this is no argument.
 
PIString argumentFullKey (const PIString &name)
 Returns full key of argument "name", or empty string if this is no argument.
 

Detailed Description

Command-Line parser.

Synopsis

This class provide handy parsing of command-line arguments. First you should add arguments to PICLI with function addArgument(). Then you can check if there is some argument in application command-line with function hasArgument(), or obtain argument value by argumentValue().

Example

int main(int argc, char ** argv) {
PICLI cli(argc, argv);
cli.addArgument("console");
cli.addArgument("debug");
cli.addArgument("Value", "v", "value", true);
if (cli.hasArgument("console"))
piCout << "console active";
if (cli.hasArgument("debug"))
piCout << "debug active";
piCout << "Value =" << cli.argumentValue("Value");
return 0;
}
Command-Line parser.
Definition: picli.h:36
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut)
Definition: picout.h:35

These executions are similar:

a.out -cd -v 10
a.out --value 10 -dc
a.out -c -v 10 -d
a.out --console -d -v 10
a.out --debug -c --value 10