https://github.com/j-city/argparse
Simple arg parse for C++
https://github.com/j-city/argparse
Last synced: 6 months ago
JSON representation
Simple arg parse for C++
- Host: GitHub
- URL: https://github.com/j-city/argparse
- Owner: J-CITY
- License: mit
- Created: 2019-07-27T02:13:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-06T08:27:05.000Z (over 1 year ago)
- Last Synced: 2025-07-26T15:54:25.202Z (about 1 year ago)
- Language: C++
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ArgParse
Simple arg parser for C++
## Base example
```c++
#include "argParse.h"
using namespace std;
using namespace ap;
int main(int argc, char* argv[]) {
ArgParse ap("APP NAME", "APP DESCRIPTION");
ap.addArg({"-i", "--int"}, [](const auto& val) {
cout << val << endl;
}, 13, "int val");
ap.addArg({"-f", "--float"}, [](const auto& val) {
cout << val << endl;
}, 0.0f, "float val");
ap.addArg({"-b", "--bool"}, [](const auto& val) {
cout << val << endl;
}, 0.0f, "bool val");
ap.addArg({"-s"}, [](const auto& val) {
cout << val << endl;
}, "", "string val");
ap.parse(argc, argv);
return 0;
}
```
## Parse argument by key
```c++
#include "argParse.h"
using namespace std;
using namespace ap;
int main(int argc, char* argv[]) {
ArgParse ap("APP NAME", "APP DESCRIPTION", "APP EPILOG");
ap.addArg({"-i", "--int"}, [](const auto& val) {
cout << val << endl;
}, 13, "int val");
// set 'false' flag for don`t call callbacks when args parse
ap.parse(argc, argv, false);
...
// get argument peyload by key
const auto& payload = ap.getPayload("-i");
// get argument payload type string by key
const auto& typeStr = ap.getPayloadTypeStr("-i");
// run argument callback by key
ap.run("-i");
return 0;
}
```
## Other features
```c++
#include "argParse.h"
using namespace std;
using namespace ap;
int main(int argc, char* argv[]) {
ArgParse ap("APP NAME", "APP DESCRIPTION", "APP EPILOG");
ap.addArg({"-i", "--int"}, [](const auto& val) {
cout << val << endl;
}, 13, "int val");
// set custom print app information, when call with '-h' or '--help' argument
ap.setCustomHelpPrinter([](const std::string& data, const std::string& epilog) {
std::cout << data << "\n\n" << epilog << std::endl;
});
// set custom type for parse
ap.addTypeParser>([](
const ArgStr& cmd,
std::map& payloadMap,
int&i, int argc, char* argv[])\
{
// some code
});
ap.parse(argc, argv, );
return 0;
}
```