An open API service indexing awesome lists of open source software.

https://github.com/p0dalirius/lib-parseargs

A simple library to parse command line arguments in C++.
https://github.com/p0dalirius/lib-parseargs

arguments cpp libra parse

Last synced: 8 months ago
JSON representation

A simple library to parse command line arguments in C++.

Awesome Lists containing this project

README

          

# lib-parseargs


A simple library to parse command line arguments in C++.


GitHub release (latest by date)

YouTube Channel Subscribers


**Note:** Use at least c++17.

## Features

- [x] Optional or required arguments, with default values.
- [x] Positional arguments.
- [x] Default help option (BooleanSwitch) `-h` or `--help` to display help message.
- [x] Parsing of arguments and printing of help message if missing mandatory arguments.b

![image](./.github/example.png)

## Example code

```cpp
#include
#include "ArgumentsParser/ArgumentsParser.h"

ArgumentsParser parseArgs(int argc, char* argv[]) {
ArgumentsParser parser = ArgumentsParser();

parser.add_positional_string_argument("mode", "Operation mode");
parser.add_positional_string_argument("another", "Another positional");

parser.add_string_argument("target", "-t", "--target", "", true, "IP or adress of the target machine");
parser.add_int_argument("port", "-p", "--port", "", true, "Port of the target machine");

parser.add_boolean_switch_argument("verbose", "-v", "--verbose", false, false, "Verbose mode.");

parser.parse_args(argc, argv);
return parser;
}

int main(int argc, char* argv[])
{
ArgumentsParser parser = parseArgs(argc, argv);

if (std::get(parser.get_value("verbose")) == true) {
std::cout << "[verbose] Mode verbose started.\n";
}

std::cout << std::get(parser.get_value("port")) << "\n";

parser.debug();
}

```

Output:

```
C:\Users\dev\> .\PocArgs.exe
Usage: PocArgs.exe [-p port] [-t target] [-v verbose]

Positional arguments:
Operation mode
Another positional

Required arguments:
-t, --target IP or adress of the target machine
-p, --port Port of the target machine

Optional arguments:
-v, --verbose Verbose mode. (default: false)

```