Skip to content

Commit fe2d2e1

Browse files
authored
Update README.md
1 parent afa1695 commit fe2d2e1

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

README.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ A simple, minimalistic but still powerful command line parser in less than 100 l
55
The library is header-only and only depends on the C++11 STL. This is not intended as a replacement for big libraries (e.g. boost::filesystem), rather as an option for quick tests and small projects.
66

77
***Features***
8-
9-
* *organize flags in groups*
10-
* *mark groups as required, optional or "any of"*
11-
* *add flags and their descriptions to the groups*
12-
* *check if all flags are valid*
8+
* *check if a flag exists*
139
* *get single parameter from flags*
1410
* *get multiple parameters from flags*
11+
* *organize flags in groups and mark them as required, optional or "any of"*
12+
* *add flags to the groups, and optionally their alternative flag and their description*
13+
* *automatically check if all flags are valid*
14+
* *automatically print help/usage messages*
1515

1616
## Platforms
1717
You will need a C++ compiler that supports C++11 regex, e.g. Clang >3.6 or GCC >4.9.
@@ -23,24 +23,45 @@ Automatic [unit tests](https://github.com/MichaelGrupp/MiniCommander/blob/master
2323
## Installation
2424
Just drop the header file [MiniCommander.hpp](https://github.com/MichaelGrupp/MiniCommander/blob/master/MiniCommander.hpp) in your project and include it in your program.
2525

26-
## Supported Formats
27-
* single flags
28-
* can be named arbitrarily, e.g. `-f` or long version `--flag`
29-
* check existence of a single flag with `optionExists("--flag")`
30-
* UNIX style multiple single flags
31-
* `-xyz` will be parsed like `-x -y -z`, `--xyz` won't
32-
* activate this behaviour by setting the optional `unixFlags`parameter of the constructor to `true`
33-
* single parameters
34-
* a parameter appears after its flag, e.g.: `--param 100` or `--param=100`
35-
* the parameter string can be accessed with `getParameter("--param")`
36-
* multiple parameters
37-
* multiple parameters appear after their flag, e.g. `--multi first second third`
38-
* `getMultiParameters("--multi")` returns the string vector of multiple parameters
39-
40-
The `checkFlags()` function checks if all required flags were given by the user. If parameters were not given, the parameter string returned by `getParameter` (or vector by `getMultiParameters`) is empty.
26+
## Supported Formats for Arguments
27+
28+
By default, flags can be name arbitrarily. Single parameters appear after a flag (here: `-d`). Multiple space-separated parameters are also possible (here after `-f`).
29+
```
30+
-x -y -z -d param -f param1 param2 param3
31+
-x -y -z -d=param -f=param1 param2 param3
32+
```
33+
By setting the optional `unixFlags`parameter of the class constructor to `true`, multiple options can be combined if they're defined in single dash format (`-*`):
34+
```
35+
-xyz -d param
36+
-xyzd=param
37+
-xyzd param
38+
```
39+
which behaves the same as `-x -y -z -d=param`.
40+
41+
* check existence of a single flag `-x` with `optionExists("-x")`
42+
* a parameter string can be accessed with `getParameter("-d")`
43+
* `getMultiParameters("-f")` returns the parameter string vector of a multiple parameter flag
44+
45+
If parameters were not given, the parameter string returned by `getParameter` (or vector by `getMultiParameters`) is empty.
46+
47+
## Grouping Options with Policies
48+
The `checkFlags()` function automatically checks if all required flags were given by the user. Furthermore, automatic help messages can be generated with `printHelpMessage`.
49+
50+
To use these features, the command line options must be first grouped by their check policy:
51+
* ***required*** - all options of this group must be given
52+
* ***optional*** - giving these options is not mandatory
53+
* ***anyOf*** - at least one option of the group must be given
54+
55+
Example of a required option group:
56+
```c++
57+
OptionGroup requiredExample(Policy::required, "required options");
58+
paths.addOption("-d", "first required argument");
59+
paths.addOption("-f", "other required argument", "--flag");
60+
```
61+
Note that an **optional long alternative** `--flag` of the `-f` flag was added. This group can now be added to a *MiniCommander* instance via `addOptionGroup`.
4162
4263
## Example Usage
43-
This code example [test.cpp](https://github.com/MichaelGrupp/MiniCommander/blob/master/test/test.cpp) shows how to use the command line interface functions offered by MiniCommander:
64+
This code example [test.cpp](https://github.com/MichaelGrupp/MiniCommander/blob/master/test/test.cpp) shows how to use all of the command line interface functions offered by MiniCommander:
4465
4566
```c++
4667
#include <iostream>

0 commit comments

Comments
 (0)