]> Creatis software - creaImageIO.git/blob - appli/gimmick/main.cxx
*** empty log message ***
[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     ("sync,s","Synchronizes the local database with the files")
31     ("recurse,r","Recurse into sub-directories  (default=off)");
32   
33   //Describes third group of options
34   po::options_description option("OPTIONS");
35   option.add_options()
36     ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
37     ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')");
38   
39   
40   //Adds the groups into a big one
41   po::options_description cmdline_options;
42   cmdline_options.add(generic).add(command).add(option);
43   
44   //Adds the corresponding variables
45   po::variables_map vm;
46   po::store(po::parse_command_line(ac, av, cmdline_options), vm);
47   po::notify(vm);    
48   
49   //Does something on each option
50   //GENERIC
51   if (vm.count("help")) {
52     cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
53     cout << cmdline_options << "\n";
54   }
55   if (vm.count("version")) {
56     cout << "gimmick 0.1.0\n";
57   }
58   
59   //OPTIONS
60   if (vm.count("verbose")) {
61     g.SetMessageLevel(verb);
62     cout << "Verbose level is now "<<verb<<"\n";
63   }
64   if (vm.count("debug")) {
65     g.SetDebugMessageLevel(deb);
66     cout << "Debug level is now "<<deb<<"\n";
67   }
68   
69   //COMMANDS
70   if (  vm.count("print")
71         ||vm.count("file")
72         ||vm.count("dir")
73         ||vm.count("sync")
74         )
75
76     try
77       {
78         g.Initialize();
79         if (vm.count("print")) {
80           g.GetTreeHandler(handler)->LoadChildren(0,0);
81           g.Print(handler);
82         }
83         if (vm.count("file")) {
84           std::vector<std::string> files=vm["file"].as< vector<string> >();
85           g.AddFiles(handler,files);
86         }
87         if (vm.count("dir")) {
88           std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
89           g.AddDir(handler,dirs.front(), vm.count("recurse"));
90         }
91         if (vm.count("sync")) {
92           g.Synchronize(true,g.GetTreeHandler(handler));
93         }       
94         g.Finalize();
95       }
96     catch (crea::Exception e)
97       {
98         e.Print();
99       }
100   
101   return 0;
102 }