Show HN: Header-only, extensible C++17 argument parser
github.com
github.com
Github has at least three C++ implementations of "argparse". Here's a header-only one.[2]
[1] https://docs.python.org/3/library/argparse.html [2] https://github.com/hbristow/argparse
// Could provide more detailed usage if wanted.
constexpr char USAGE[] = "./program --input_path input --output_path output";
int main(int argc, char** argv) {
const flags::args args(argc, argv);
const auto input_path = args.get<std::string>("input_path");
const auto output_path = args.get<std::string>("output_path");
if (!input_path || !output_path) {
std::cerr << USAGE << std::endl;
return 1;
}
std::cout << "success: " << *input_path << " to " << *output_path
<< std::endl;
return 0;
}
The primary goal of this is to be simple to use and implement in your project, but I can see the use of a simple validation function which provides the same functionality as the above.