CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CLIParse.cc
Go to the documentation of this file.
1 #include "casm/app/CLIParse.hh"
2 
3 #include <boost/program_options.hpp>
4 
5 #include "casm/casm_io/Log.hh"
7 
8 namespace CASM {
9 
11 CLIParse::CLIParse(int _argc, char **_argv)
12  : m_argc(_argc), m_argv(_argv), m_parse_result(0), m_free_p(false) {}
13 
15 CLIParse::CLIParse(std::string _args) : m_free_p(false) {
16  // parse _args -> argc, argv
17  m_parse_result = wordexp(_args.c_str(), &m_p, 0);
18  if (m_parse_result) {
19  err_log() << "Error parsing query: '" << _args << "'" << std::endl;
20  err_log() << "wordexp() error: " << m_parse_result << std::endl;
21  switch (m_parse_result) {
22  case 1: {
23  err_log() << "Check for illegal unescaped characters: |, &, ;, <, >, "
24  "(, ), {, }"
25  << std::endl;
26  break;
27  }
28  default: {
29  err_log() << "Check 'man wordexp' for error code meaning" << std::endl;
30  }
31  }
32  return;
33  }
34 
35  m_free_p = true;
36  m_argc = m_p.we_wordc;
37  m_argv = m_p.we_wordv;
38 }
39 
41  if (m_free_p) {
42  wordfree(&m_p);
43  }
44 }
45 
48 void parse_args(Completer::OptionHandlerBase &opt, std::string args) {
49  CLIParse parse(args);
50  po::store(po::parse_command_line(parse.argc(), parse.argv(), opt.desc()),
51  opt.vm());
52  // gets default values
53  po::notify(opt.vm());
54 }
55 } // namespace CASM
char ** m_argv
Definition: CLIParse.hh:28
CLIParse(int _argc, char **_argv)
Non-owning.
Definition: CLIParse.cc:11
int m_parse_result
Definition: CLIParse.hh:32
wordexp_t m_p
Definition: CLIParse.hh:35
const po::options_description & desc()
Get the program options, filled with the initialized values.
Definition: Handlers.cc:321
po::variables_map & vm()
Get the variables map.
Definition: Handlers.cc:310
Main CASM namespace.
Definition: APICommand.hh:8
void parse_args(Completer::OptionHandlerBase &opt, std::string args)
Definition: CLIParse.cc:48
void parse(InputParser< ConfigEnumOptions > &parser, std::string method_name, PrimClex const &primclex, DataFormatterDictionary< Configuration > const &dict)
Log & err_log()
Definition: Log.hh:426