diff options
author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2025-08-26 13:06:57 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-09-01 20:02:59 +0100 |
commit | e93b2fe92eb172d7c7b76209bf489d9c0da59cca (patch) | |
tree | 7089fb5b49325b00dff5a26439fec49bb6bc8ffc /src | |
parent | 828c158519cc4182277eca1d00ec7dd9fce4986c (diff) | |
download | webstat-e93b2fe92eb172d7c7b76209bf489d9c0da59cca.tar.bz2 webstat-e93b2fe92eb172d7c7b76209bf489d9c0da59cca.tar.xz webstat-e93b2fe92eb172d7c7b76209bf489d9c0da59cca.zip |
Add basic boost::program_options support
Diffstat (limited to 'src')
-rw-r--r-- | src/Jamfile.jam | 1 | ||||
-rw-r--r-- | src/webstat_logger_main.cpp | 27 |
2 files changed, 27 insertions, 1 deletions
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 : <library>webstat <library>..//dbpp-postgresql + <library>..//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 <boost/program_options.hpp> #include <format> +#include <iostream> #include <pq-connection.h> #include <sys/utsname.h> @@ -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<std::string>(), "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<std::string>().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<PQ::Connection>("dbname=webstat user=webstat"); WebStat::Ingestor {getHostname(false), dbconn}.ingestLog(stdin); + return EXIT_SUCCESS; } |