There can be only one (filename convention)
[mussa.git] / alg / parse_options.cpp
1 #include <boost/program_options.hpp>
2 namespace po = boost::program_options;
3
4 #include <string>
5 #include <iostream>
6
7 #include "alg/mussa.hpp"
8 #include "alg/parse_options.hpp"
9
10 Mussa *initialize_mussa(int argc, char **argv)
11 {
12   po::options_description options("Mussa options");
13   po::positional_options_description pos_options;
14   pos_options.add("run-analysis", -1);
15
16   options.add_options()
17     ("help", "help message")
18     ("run-analysis,p", po::value<std::string>(), 
19      "run an analysis defined by the mussa parameter file")
20     ("view-analysis", po::value<std::string>(),
21      "load a previously run analysis")
22   ;
23
24   po::variables_map vm;
25   po::store(po::command_line_parser(argc, argv).options(options).positional(pos_options).run(), vm);
26   po::notify(vm);
27
28   if (vm.count("help")) {
29     std::cout << options << std::endl;
30     return 0;
31   }
32
33   Mussa *m = new Mussa();
34   // currently we can only have one analysis loaded, so 
35   // running trumps viewing.
36   if (vm.count("run-analysis")) {
37     m->load_mupa_file( vm["run-analysis"].as< std::string >() );
38     std::cout << "I apologize for blocking the gui while running the analysis"
39               << std::endl;
40     m->analyze();
41   }
42   else if (vm.count("view-analysis")) {
43     m->load( vm["view-analysis"].as< std::string >() );
44   }
45   return m;
46 }
47