allow running without using the gui
[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     ("no-gui", "terminate without running an analysis")
23   ;
24
25   po::variables_map vm;
26   po::store(po::command_line_parser(argc, argv).options(options).positional(pos_options).run(), vm);
27   po::notify(vm);
28
29   if (vm.count("help")) {
30     std::cout << options << std::endl;
31     return 0;
32   }
33
34   Mussa *m = new Mussa();
35   // currently we can only have one analysis loaded, so 
36   // running trumps viewing.
37   if (vm.count("run-analysis")) {
38     m->load_mupa_file( vm["run-analysis"].as< std::string >() );
39     std::cout << "I apologize for blocking the gui while running the analysis"
40               << std::endl;
41     m->analyze();
42   }
43   else if (vm.count("view-analysis")) {
44     m->load( vm["view-analysis"].as< std::string >() );
45   }
46   if (vm.count("no-gui")) {
47     return 0;
48   } else {
49     return m;
50   }
51 }
52