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 ("files,f",po::value< vector<string> >(),"Adds the file(s) to the local database")
29 ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
30 ("sync,s",po::value< vector<string> >(),"Synchronizes the local database with the files")
31 ("copy,c",po::value< vector<string> >(),"Copies the files into a local directory");
33 //Describes third group of options
34 po::options_description option("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 ("recurse,r","Recurse into sub-directories (default=off)")
39 ("repair,R","Repair the database (on synchronization) (default=off)")
40 ("check,C","Check for attribute differences (on synchronization) (default=off)")
41 ("handler,H",po::value<string>(&handler),"Handler name (default=`Local database')");
43 //Adds the groups into a big one
44 po::options_description cmdline_options;
45 cmdline_options.add(generic).add(command).add(option);
47 //Adds the corresponding variables
49 po::store(po::parse_command_line(ac, av, cmdline_options), vm);
53 //Does something on each option
55 if (vm.count("help")) {
56 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
57 cout << cmdline_options << "\n";
59 if (vm.count("version")) {
60 cout << "gimmick 0.1.0\n";
64 if (vm.count("verbose")) {
65 g.SetMessageLevel(verb);
66 cout << "Verbose level is now "<<verb<<"\n";
68 if (vm.count("debug")) {
69 g.SetDebugMessageLevel(deb);
70 cout << "Debug level is now "<<deb<<"\n";
74 if ( vm.count("print")
85 if (vm.count("print")) {
86 g.GetTreeHandler(handler)->LoadChildren(0,0);
89 if (vm.count("file")) {
90 std::vector<std::string> files=vm["file"].as< vector<string> >();
91 g.AddFiles(handler,files);
93 if (vm.count("dir")) {
94 std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
96 std::stringstream out;
97 out<<vm.count("recurse");
98 if(out.str().compare("1")==0){recu=true;}
99 g.AddDir(handler,dirs.front(), recu);
101 if (vm.count("sync")) {
104 std::vector<std::string> name=vm["sync"].as< vector<string> >();
105 std::stringstream out;
106 out<<vm.count("repair");
107 if(out.str().compare("1")==0){rep=true;}
108 std::stringstream out2;
109 out2<<vm.count("check");
110 if(out2.str().compare("1")==0){chk=true;}
111 cout<<g.Synchronize(name.front(),rep,chk)<<"\n";
113 if (vm.count("copy")) {
114 std::vector<std::string> name=vm["copy"].as< vector<string> >();
115 g.CopyFiles(name,handler);
119 catch (crea::Exception e)