C++ cli parser
A small C++ library to simplify parsing arguments
#include "CppClip.hpp"
CppClip::ArgumentParser parser("program");
parser.addDescription("Program description");
parser.addEpilogue("Epilogue");
The parser uses method chaining to specify parameters for arguments
Arguments must be added in reverse order! (bottom to top gets processed left to right)
parser.add("ip").nargs(2);
parser.add("-v", "--version").help("show version and exit");
parser.add("-h", "--help").help("Show help and exit");
parser.add("-s").help("something");
parser.add("number");
Exception handling is done using a try catch block
try {
...
} catch (std::exception &e) {
parser.printHelp();
std::cerr << "\nError: " << e.what() << '\n';
exit(1);
}
parser.parse(argc, argv);
// The long option is checked automatically
if (parser.isSet("-h")) {
parser.printHelp();
exit(0);
}
const std::vector<std::string> &ip = parser.getPositional("ip");
- Ability to add multiple optional positional arguments