From 88708a8aa6a33f265ff990102b44a9a51e3bf4bb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 3 Jun 2021 00:19:50 +0100 Subject: Get upstream from DB Adds options from command line and a few supporting tweaks --- main/Jamfile.jam | 2 +- main/main.cpp | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'main') diff --git a/main/Jamfile.jam b/main/Jamfile.jam index d03d005..7adaddb 100644 --- a/main/Jamfile.jam +++ b/main/Jamfile.jam @@ -1,2 +1,2 @@ -exe mygrate : main.cpp : ../lib//mygrate ; +exe mygrate : main.cpp : ../lib//mygrate ..//po ; #run main.cpp : : : ../lib//mygrate ; diff --git a/main/main.cpp b/main/main.cpp index bdcda75..815ca67 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,10 +1,38 @@ -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; int -main(int, char **) +main(int argc, char ** argv) { - MyGrate::Input::ReplicationStream rs {"192.168.1.38", "repl", "r3pl", 3306}; - MyGrate::Output::DumpToConsole dtc; - rs.readEvents(dtc); + std::string pgconn; + uint64_t sourceid {}; + bool help {}; + po::options_description opts("MyGrate"); + opts.add_options()("postgresql,p", po::value(&pgconn)->required(), "Target PostgreSQL connection string")( + "sourceid,s", po::value(&sourceid)->default_value(1), "Source identifier")("help,h", + po::value(&help)->zero_tokens(), "Help"); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(opts).run(), vm); + + if (vm.count("help")) { + std::cout << opts; + return EXIT_SUCCESS; + } + po::notify(vm); + + MyGrate::Output::Pq::UpdateDatabase ud {pgconn.c_str(), sourceid}; + auto src {ud.getSource()}; + src->readEvents(ud); + + return EXIT_SUCCESS; } -- cgit v1.2.3