Single-file, header-only library of a POSIX getopt workalike.
#include <getopt.hpp>
// command -v -o arg ...
int main(int argc, char** argv)
{
cxx::getopt getopt;
bool verbose = false;
char const* output = "default";
for (int opt; (opt = getopt(argc, argv, "vo:")) != -1; ) {
switch (opt) {
case 'v':
verbose = true;
break;
case 'o':
output = getopt.optarg;
break;
case '?':
// Error
}
}
argc -= getopt.optind;
argv += getopt.optind;
// Now you can access positional arguments: argv[0], ..., argv[argc - 1]
}
Just download getopt.hpp into your include directory.
License text is included in the header file and the license is permissive (the Boost License), so you do not need to do anything on redistribution.
git clone https://github.com/snsinfu/cxx-getopt.git
cd cxx-getopt/tests
make
Boost Software License, Version 1.0.