Skip to content

Commit

Permalink
Check for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
qprostu committed Jan 27, 2018
1 parent b3d9f55 commit cbd93f6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sqlproxy.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
#include <iostream>
#include <boost/program_options.hpp>


namespace {
namespace po = boost::program_options;

void init_all(int argc, char **argv) {
po::options_description desc("SQLProxy command line options");
std::string config;
desc.add_options()
("help,h", "show help message")
// ("config,c", po::value<std::string>(&config)->required(), "path to configuration")
("config,c", "path to configuration")
("config,c", po::value<std::string>(&config)->required(), "path to configuration")
;

auto options = po::command_line_parser(argc, argv).options(desc).run();
po::variables_map vm;
po::store(options, vm);
po::notify(vm);

if (vm.count("help")) {
std::cerr << desc << "\n";
exit(1);
}

if (!vm.count("config")) {
std::cerr << " error: the option '--config' is required but missing\n";
exit(1);
}
po::notify(vm);

std::string config = vm["config"].as<std::string>();
std::cout << "configuration: '" << config << "'\n";
}
}


int main(int argc, char **argv) {
init_all(argc, argv);
try {
init_all(argc, argv);
} catch (po::required_option &err) {
std::cerr << " error: " << err.what() << "\n";
} catch (std::exception &e) {
std::cerr << e.what() << "\n";
}
}

0 comments on commit cbd93f6

Please sign in to comment.