![]() |
PIP 5.6.1
Platform-Independent Primitives
|
Command-line argument parser class The PICLI class provides convenient parsing of command-line arguments. It supports short keys (e.g., -c), full keys (e.g., –console), and arguments with/without values. 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. | |
| PIString | mandatoryArgument (int index) |
| Returns mandatory positional argument by index. | |
| PIString | optionalArgument (int index) |
| Returns optional positional argument by index. | |
| const PIStringList & | rawArguments () |
| Returns unparsed command-line arguments. | |
| const PIStringList & | mandatoryArguments () |
| Returns all mandatory positional arguments. | |
| const PIStringList & | optionalArguments () |
| Returns all optional positional 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. | |
| const PIString & | shortKeyPrefix () const |
| Returns prefix used for short keys. | |
| const PIString & | fullKeyPrefix () const |
| Returns prefix used for full keys. | |
| int | mandatoryArgumentsCount () const |
| Returns expected count of mandatory positional arguments. | |
| int | optionalArgumentsCount () const |
| Returns expected count of optional positional arguments. | |
| void | setShortKeyPrefix (const PIString &prefix) |
| Sets prefix used for short keys such as "-d". | |
| void | setFullKeyPrefix (const PIString &prefix) |
| Sets prefix used for full keys such as "--debug". | |
| void | setMandatoryArgumentsCount (const int count) |
| Sets count of mandatory positional arguments collected before optional ones. | |
| void | setOptionalArgumentsCount (const int count) |
| Sets count of optional positional arguments. Negative value means unlimited. | |
| bool | debug () const |
| Returns debug mode flag. | |
| void | setDebug (bool debug) |
| Enables or disables debug mode. | |
| PIConstChars | className () const |
| Returns class name. | |
| PIString | name () const |
| Returns human-readable object name. | |
Command-line argument parser class The PICLI class provides convenient parsing of command-line arguments. It supports short keys (e.g., -c), full keys (e.g., –console), and arguments with/without values.
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().
These executions are similar: