cxxopts

Lightweight C++ command-line option parser for building CLI applications

brewmacoslinux
Try with needOr install directly
Source

About

Lightweight C++ command-line option parser

Examples

parse command line arguments in C++ program$ #include <cxxopts.hpp> cxxopts::Options options("program"); options.add_options()("h,help", "Print help");
add required and optional flags to CLI tool$ options.add_options()("input,i", "Input file", cxxopts::value<std::string>())("verbose,v", "Enable verbose mode", cxxopts::value<bool>()->default_value("false"));
parse arguments and handle errors$ auto result = options.parse(argc, argv); if (result.count("help")) { std::cout << options.help() << std::endl; }
validate and access parsed command line values$ std::string input = result["input"].as<std::string>(); bool verbose = result["verbose"].as<bool>();
display help message with all available options$ std::cout << options.help() << std::endl;