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++.
- Host: GitHub
- URL: https://github.com/p0dalirius/lib-parseargs
- Owner: p0dalirius
- Created: 2022-12-21T15:31:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-02T20:38:43.000Z (about 3 years ago)
- Last Synced: 2024-12-18T18:50:11.172Z (over 1 year ago)
- Topics: arguments, cpp, libra, parse
- Language: C++
- Homepage:
- Size: 38.4 MB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# lib-parseargs
A simple library to parse command line arguments in C++.
**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

## 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)
```