Death to stupid mussa pointers
[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 MussaOptions::MussaOptions()
11   : useGUI(true),
12     runAsPythonInterpeter(false)
13 {
14 }
15
16 void initialize_mussa(MussaOptions& opts, int argc, char **argv)
17 {
18   po::options_description options("Mussa options");
19   po::positional_options_description pos_options;
20   pos_options.add("run-analysis", -1);
21
22   options.add_options()
23     ("help", "help message")
24     ("run-analysis,p", po::value<std::string>(), 
25      "run an analysis defined by the mussa parameter file")
26     ("view-analysis", po::value<std::string>(),
27      "load a previously run analysis")
28     ("no-gui", "terminate without running an analysis")
29     ("python", "launch as a python interpreter")
30   ;
31
32   po::variables_map vm;
33   po::store(po::command_line_parser(argc, argv).options(options).positional(pos_options).run(), vm);
34   po::notify(vm);
35
36   if (vm.count("help")) {
37     std::cout << options << std::endl;
38     return;
39   }
40   
41   MussaRef new_mussa(new Mussa);
42   opts.analysis = new_mussa;
43
44   // currently we can only have one analysis loaded, so 
45   // running trumps viewing.
46   if (vm.count("run-analysis")) {
47     opts.analysis->load_mupa_file( vm["run-analysis"].as< std::string >() );
48     std::cout << "I apologize for blocking the gui while running the analysis"
49               << std::endl;
50     opts.analysis->analyze();
51     if (opts.analysis->is_dirty())
52       opts.analysis->save();
53   }
54   else if (vm.count("view-analysis")) {
55     opts.analysis->load( vm["view-analysis"].as< std::string >() );
56   }
57   if (vm.count("no-gui")) {
58     opts.useGUI=false;
59   }
60   if (vm.count("python")) {
61     opts.runAsPythonInterpeter = true;
62   }
63 }