https://github.com/hughperkins/argparsecpp
C++ version of Python's ArgParse
https://github.com/hughperkins/argparsecpp
Last synced: 5 months ago
JSON representation
C++ version of Python's ArgParse
- Host: GitHub
- URL: https://github.com/hughperkins/argparsecpp
- Owner: hughperkins
- License: apache-2.0
- Created: 2016-11-02T11:27:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-16T14:11:27.000Z (almost 9 years ago)
- Last Synced: 2025-05-13T02:09:14.879Z (5 months ago)
- Language: C++
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ArgParseCpp
C++ version of Python's ArgParseLoosely modelled off Python's argparse module.
I couldnt find a drop-in portable commandline parser for c++. Options that came up on stackoverflow:
- use boost
- use getoptBoost is hard to compile on Windows, so I'd prefer to avoid linking with thta. Especially for something as simple as parsing a commandline.
Getopt seems to have some combination of not being portable, being GPL-ish, and not accepting long arguments.
By comparison, ArgParseCpp:
- Apache license. Simply drop the files into your own repo. dont modify the copyright headers on them. Ideally star my repo :-)
- Doesnt need any dependencies. Well, it's sort of c++11. Thats it
- Is totally portableExample usage:
```
string requiredstring = "";
bool somebool = false;
string somestring = "";
int someint = 0;
float somefloat = 0.0f;cocl::ArgumentParser parser;
parser.add_string_argument("--requiredstring", &requiredstring)->required();
parser.add_bool_argument("--somebool", &somebool);
parser.add_string_argument("--somestring", &somestring)->help("this should be a string");
parser.add_int_argument("--someint", &someint);
parser.add_float_argument("--somefloat", &somefloat);if(!parser.parse_args(argc, argv)) {
return -1;
}cout << "requiredstring " << requiredstring << endl;
cout << "somebool " << somebool << endl;
cout << "somestring " << somestring << endl;
cout << "someint " << someint << endl;
cout << "somefloat " << somefloat << endl;
```## Build
I reckon you can just drop the files directly into your own project. So, no need to build
## Test
Run:
```
mkdir -p build
cd build
cmake ..
make
./test_argparsecpp
```