Adding catch to boost program options parser.

This commit is contained in:
Pedro Alvarez 2019-01-18 12:38:56 +00:00
parent fb9f746332
commit c5dad67a16
4 changed files with 28 additions and 10 deletions

View File

@ -173,9 +173,13 @@ void parse_args(all_args_t *args, int argc, char* argv[]) {
// parse the command line and store result in vm
bpo::variables_map vm;
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
try {
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
} catch(bpo::error &e) {
cerr<< e.what() << endl;
exit(1);
}
// help option was given - print usage and exit
if (vm.count("help")) {
cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl;

View File

@ -161,8 +161,13 @@ parse_args(all_args_t *args, int argc, char* argv[]) {
// parse the command line and store result in vm
bpo::variables_map vm;
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
try {
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
} catch(bpo::error &e) {
cerr<< e.what() << endl;
exit(1);
}
// help option was given - print usage and exit
if (vm.count("help")) {

View File

@ -129,8 +129,13 @@ parse_args(all_args_t *args, int argc, char* argv[]) {
// parse the command line and store result in vm
bpo::variables_map vm;
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
try {
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
} catch(bpo::error &e) {
cerr<< e.what() << endl;
exit(1);
}
// help option was given - print usage and exit
if (vm.count("help")) {

View File

@ -330,9 +330,13 @@ void parse_args(all_args_t* args, int argc, char* argv[])
// parse the command line and store result in vm
bpo::variables_map vm;
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
try{
bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
bpo::notify(vm);
} catch(bpo::error &e) {
cerr<< e.what() << endl;
exit(1);
}
// help option was given - print usage and exit
if (vm.count("help")) {
cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl;