From e93b2fe92eb172d7c7b76209bf489d9c0da59cca Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 26 Aug 2025 13:06:57 +0100 Subject: Add basic boost::program_options support --- Jamroot.jam | 1 + src/Jamfile.jam | 1 + src/webstat_logger_main.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Jamroot.jam b/Jamroot.jam index 1a9a214..5ec40fa 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -7,6 +7,7 @@ build-project src ; build-project test ; pkg-config.import glibmm : : glibmm-2.68 ; +lib boost_po : : shared boost_program_options ; lib adhocutil : : shared : : /usr/include/adhocutil glibmm ; lib dbppcore : : shared : : /usr/include/dbpp adhocutil ; lib dbpp-postgresql : : shared : : /usr/include/dbpp-postgresql dbppcore ; diff --git a/src/Jamfile.jam b/src/Jamfile.jam index a6abc93..38d8c37 100644 --- a/src/Jamfile.jam +++ b/src/Jamfile.jam @@ -10,4 +10,5 @@ lib webstat : ingestor.cpp logTypes.cpp sql.cpp : exe webstat_logger : webstat_logger_main.cpp : webstat ..//dbpp-postgresql + ..//boost_po ; diff --git a/src/webstat_logger_main.cpp b/src/webstat_logger_main.cpp index e4f871e..0db940a 100644 --- a/src/webstat_logger_main.cpp +++ b/src/webstat_logger_main.cpp @@ -1,5 +1,7 @@ #include "ingestor.hpp" +#include #include +#include #include #include @@ -20,8 +22,31 @@ namespace { } int -main(int, char **) +main(int argc, char ** argv) { + namespace po = boost::program_options; + po::options_description opts("WebStat logger"); + + // clang-format off + opts.add_options() + ("help,h", "Show this help message") + ("config,c", po::value(), "Read config from this config file") + ; + // clang-format on + po::variables_map optVars; + po::store(po::command_line_parser(argc, argv).options(opts).run(), optVars); + if (const auto & rcPath = optVars.find("config"); rcPath != optVars.end()) { + po::store(po::parse_config_file(rcPath->second.as().c_str(), opts), optVars); + } + + // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) + if (optVars.contains("help")) { + std::cout << opts << '\n'; + return EXIT_FAILURE; + } + po::notify(optVars); + auto dbconn = std::make_shared("dbname=webstat user=webstat"); WebStat::Ingestor {getHostname(false), dbconn}.ingestLog(stdin); + return EXIT_SUCCESS; } -- cgit v1.2.3