4 ms·
Show HN: Header-only, extensible C++17 argument parser
- sail0rm00n 10y agoBy the way, I am looking for any and all feedback and would love a code-review!
- Animats 10y agoCompare "argparse", in Python.[1] There are a number of argument parsers like this. They have some way to describe the expected form of the command line, and check it. Errors result in a "usage" message which shows the desired form of the command line in the usual "help" style. 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 https://docs.python.org/3/library/argparse.html [2] https://github.com/hbristow/argparse https://github.com/hbristow/argparse
- sail0rm00n 10y agoI agree with you, but a user can easily wrap their own to avoid the boilerplate for adding arguments. An example would be: // 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.