opt_parser.cpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------------
2 // d-SEAMS - Deferred Structural Elucidation Analysis for Molecular Simulations
3 //
4 // Copyright (c) 2018--present d-SEAMS core team
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the MIT License as published by
8 // the Open Source Initiative.
9 //
10 // A copy of the MIT License is included in the LICENSE file of this repository.
11 // You should have received a copy of the MIT License along with this program.
12 // If not, see <https://opensource.org/licenses/MIT>.
13 //-----------------------------------------------------------------------------------
14 
15 #include "opt_parser.h"
16 
17 // This creates options
18 cxxopts::ParseResult parse(int argc, char *argv[]) {
19  try {
20  cxxopts::Options options(
21  argv[0], "Structure calculations for molecular simulations");
22  options.positional_help("[optional args]").show_positional_help();
23  options.allow_unrecognised_options().add_options()(
24  "c,config", "Yaml Config",
25  cxxopts::value<std::string>()->default_value("conf.yml"))
26 
27  ("h,help", "Print help");
28  auto result = options.parse(argc, argv);
29 
30  if (result.count("help")) {
31  std::cout << options.help({"", "Group"}) << std::endl;
32  exit(0);
33  }
34  // No options
35  if (result.arguments().size() == 0) {
36  std::cout << "DO error handling" << std::endl;
37  }
38  return result;
39  } catch (const cxxopts::OptionException &e) {
40  std::cout << "error parsing options: " << e.what() << std::endl;
41  exit(1);
42  }
43 }
T endl(T... args)
cxxopts::ParseResult parse(int argc, char *argv[])
Definition: opt_parser.cpp:18