1 #include <boost/program_options.hpp>
4 namespace po = boost::program_options;
6 #include <creaImageIOGimmick.h>
7 #include <creaMessageManager.h>
11 int main(int ac, char* av[])
14 creaImageIO::Gimmick g;
16 std::string handler("Local database");
18 //Describes first group of options
19 po::options_description generic("GENERIC");
21 ("help,h", "Print help and exit")
22 ("version,V", "Print version and exit");
24 //Describes second group of options
25 po::options_description command("COMMANDS");
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 ("repair,R","Repair the database (on synchronization) (default=off)")
33 ("check,c","Check for attribute differences (on synchronization) (default=off)");
36 //Describes third group of options
37 po::options_description option("OPTIONS");
39 ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
40 ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')");
42 //Adds the groups into a big one
43 po::options_description cmdline_options;
44 cmdline_options.add(generic).add(command).add(option);
46 //Adds the corresponding variables
48 po::store(po::parse_command_line(ac, av, cmdline_options), vm);
51 //Does something on each option
53 if (vm.count("help")) {
54 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
55 cout << cmdline_options << "\n";
57 if (vm.count("version")) {
58 cout << "gimmick 0.1.0\n";
62 if (vm.count("verbose")) {
63 g.SetMessageLevel(verb);
64 cout << "Verbose level is now "<<verb<<"\n";
66 if (vm.count("debug")) {
67 g.SetDebugMessageLevel(deb);
68 cout << "Debug level is now "<<deb<<"\n";
72 if ( vm.count("print")
81 if (vm.count("print")) {
82 g.GetTreeHandler(handler)->LoadChildren(0,0);
85 if (vm.count("file")) {
86 std::vector<std::string> files=vm["file"].as< vector<string> >();
87 g.AddFiles(handler,files);
89 if (vm.count("dir")) {
90 std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
92 std::stringstream out;
93 out<<vm.count("recurse");
94 if(out.str().compare("1")==0){recu=true;}
95 g.AddDir(handler,dirs.front(), recu);
97 if (vm.count("sync")) {
100 std::stringstream out;
101 out<<vm.count("repair");
102 if(out.str().compare("1")==0){rep=true;}
103 std::stringstream out2;
104 out2<<vm.count("check");
105 if(out2.str().compare("1")==0){chk=true;}
106 g.Synchronize(rep,chk);
110 catch (crea::Exception e)