You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-21Lines changed: 42 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ A simple, minimalistic but still powerful command line parser in less than 100 l
5
5
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.
6
6
7
7
***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*
13
9
**get single parameter from flags*
14
10
**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*
15
15
16
16
## Platforms
17
17
You will need a C++ compiler that supports C++11 regex, e.g. Clang >3.6 or GCC >4.9.
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.
25
25
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
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`.
41
62
42
63
## 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:
0 commit comments