opt_parser.cpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------------
2 // d-SEAMS is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // A copy of the GNU General Public License is available at
8 // http://www.gnu.org/licenses/
9 //-----------------------------------------------------------------------------------
10 
11 #include "opt_parser.h"
12 
13 // This creates options
14 cxxopts::ParseResult parse(int argc, char *argv[]) {
15  try {
16  cxxopts::Options options(
17  argv[0], "Structure calculations for molecular simulations");
18  options.positional_help("[optional args]").show_positional_help();
19  options.allow_unrecognised_options().add_options()(
20  "c,config", "Yaml Config",
21  cxxopts::value<std::string>()->default_value("conf.yml"))
22 
23  ("h,help", "Print help");
24  auto result = options.parse(argc, argv);
25 
26  if (result.count("help")) {
27  std::cout << options.help({"", "Group"}) << std::endl;
28  exit(0);
29  }
30  // No options
31  if (result.arguments().size() == 0) {
32  std::cout << "DO error handling" << std::endl;
33  }
34  return result;
35  } catch (const cxxopts::OptionException &e) {
36  std::cout << "error parsing options: " << e.what() << std::endl;
37  exit(1);
38  }
39 }
T endl(T... args)
cxxopts::ParseResult parse(int argc, char *argv[])
Definition: opt_parser.cpp:14