]> Creatis software - creaImageIO.git/blob - appli/gimmick/main.cxx
cecd0f76ba6ac8503f6e7d24fb8cfac8fae10caf
[creaImageIO.git] / appli / gimmick / main.cxx
1 #include <boost/program_options.hpp>
2
3 using namespace boost;
4 namespace po = boost::program_options;
5
6 #include <creaImageIOGimmick.h>
7 #include <creaMessageManager.h>
8
9 using namespace std;
10
11 int main(int ac, char* av[])
12 {
13
14         creaImageIO::Gimmick g;
15         int verb,deb;
16         std::string handler("Local database");
17
18         //Describes first group of options
19         po::options_description generic("GENERIC");
20         generic.add_options()
21     ("help,h", "Print help and exit")
22         ("version,V", "Print version and exit");
23
24         //Describes second group of options
25         po::options_description command("COMMANDS");
26         command.add_options()
27     ("print,p","Prints the local database tree  (default=off)")
28     ("file,f",po::value< vector<string> >(),"Adds the file to the local database")
29         ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
30         ("recurse,r","Recurse into sub-directories  (default=off)");
31
32         //Describes third group of options
33         po::options_description option("OPTIONS");
34         option.add_options()
35     ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
36         ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')");
37
38
39         //Adds the groups into a big one
40         po::options_description cmdline_options;
41         cmdline_options.add(generic).add(command).add(option);
42
43         //Adds the corresponding variables
44         po::variables_map vm;
45         po::store(po::parse_command_line(ac, av, cmdline_options), vm);
46         po::notify(vm);    
47
48         //Does something on each option
49         //GENERIC
50         if (vm.count("help")) {
51                 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
52                 cout << cmdline_options << "\n";
53         }
54         if (vm.count("version")) {
55                 cout << "gimmick 0.1.0\n";
56         }
57
58         //OPTIONS
59         if (vm.count("verbose")) {
60                 g.SetMessageLevel(verb);
61                 cout << "Verbose level is now "<<verb<<"\n";
62         }
63         if (vm.count("debug")) {
64                 g.SetDebugMessageLevel(deb);
65                 cout << "Debug level is now "<<deb<<"\n";
66         }
67
68         //COMMANDS
69         if(vm.count("print")||vm.count("file")||vm.count("dir"))
70         try
71     {
72      g.Initialize();
73         if (vm.count("print")) {
74                 g.GetTreeHandler(handler)->LoadChildren(0,0);
75                 g.Print(handler);
76         }
77         if (vm.count("file")) {
78                 std::vector<std::string> files=vm["file"].as< vector<string> >();
79         g.AddFiles(handler,files);
80         }
81         if (vm.count("dir")) {
82                 std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
83                 g.AddDir(handler,dirs.front(), vm.count("recurse"));
84         }
85          g.Finalize();
86     }
87   catch (crea::Exception e)
88     {
89       e.Print();
90     }
91
92   return 0;
93 }