I'm trying to figure out the best way to exit my program cleanly after printing the CLI help information in my program. Currently it looks like this.
int main(int argc, *char[] argv) {
try {
std::string settings_file = process_args(argc, argv);
do_more_stuff();
...
...
} catch (...) {
std::cerr << "Error" << std::endl;
return (EXIT_FAILURE)
}
}
std::string process_args(int argc, char *argv[]) {
boost::program_options::options_description desc("Program options");
desc.add_options()("help,h", "Print usage message")(
"settings,s", boost::program_options::value<std::string>(),
"Specify settings file");
boost::program_options::variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
---->!!!!!!!! WHAT DO I DO HERE TO GET OUT !!!!!!!!<----
}
if (vm.count("settings")) {
std::cout << "Settings file " << vm["settings"].as<std::string() << std::endl;
return vm["settings"].as<std::string>();
} else {
throw std::runtime_error("Settings file must be specified.");
}
}
So my question is after I print the CLI 'help' message what do I do to exit my program?
Should my function not be returning std::string and just return an error code?
Should I throw an exception and catch it in main and then exit?
Is there a much nicer / better way to do it?
Thanks in advance.