Skip to content

Commit 3972a3a

Browse files
committed
Update README.md
1 parent 8dd451b commit 3972a3a

1 file changed

Lines changed: 49 additions & 4 deletions

File tree

README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,45 @@
33

44
A simple header only command line argument parser
55

6-
## Usage
7-
Here is a simple example
6+
## Usage:
7+
### Simple example
8+
```cpp
9+
#include "argparse.h"
10+
11+
#include <iostream>
12+
13+
int main(int argc, char* argv[]) {
14+
ArgumentParser parser("Argument parser example");
15+
parser.add_argument("-v", // short argument
16+
"--verbose", // long argument
17+
"Verbose level", // description
18+
false // is required
19+
);
20+
parser.parse(argc, argv);
21+
22+
if (parser.exists("verbose")) {
23+
switch (parser.get<unsigned int>("verbose")) {
24+
case 2:
25+
std::cout << "an even more verbose string" << std::endl;
26+
case 1:
27+
std::cout << "a verbose string" << std::endl;
28+
default:
29+
std::cout << "some verbosity" << std::endl;
30+
}
31+
}
32+
}
33+
```
34+
Example output:
35+
```
36+
> program -v 2
37+
an even more verbose string
38+
a verbose string
39+
some verbosity
40+
> program --verbose
41+
so much verbosity
42+
```
43+
44+
### Full example
845
946
```cpp
1047
#include "argparse.h"
@@ -57,5 +94,13 @@ int main(int argc, char* argv[]) {
5794
}
5895
```
5996

60-
## Compiling
61-
Just add `argparse.h` to your include path. No longer requires compiler support for `<regex>`
97+
## Building:
98+
### In your own project
99+
Just add `argparse.h` to your include path.
100+
101+
### Example and Tests with CMake
102+
```
103+
mkdir build && cd build
104+
cmake ..
105+
make
106+
```

0 commit comments

Comments
 (0)