opt_parser.h File Reference
#include <cxxopts.hpp>
+ Include dependency graph for opt_parser.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

cxxopts::ParseResult parse (int argc, char *argv[])
 

Function Documentation

◆ parse()

cxxopts::ParseResult parse ( int  argc,
char *  argv[] 
)

Definition at line 14 of file opt_parser.cpp.

14  {
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)
T exit(T... args)