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)");
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')");
40 //Adds the groups into a big one
41 po::options_description cmdline_options;
42 cmdline_options.add(generic).add(command).add(option);
44 //Adds the corresponding variables
46 po::store(po::parse_command_line(ac, av, cmdline_options), vm);
49 //Does something on each option
51 if (vm.count("help")) {
52 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
53 cout << cmdline_options << "\n";
55 if (vm.count("version")) {
56 cout << "gimmick 0.1.0\n";
60 if (vm.count("verbose")) {
61 g.SetMessageLevel(verb);
62 cout << "Verbose level is now "<<verb<<"\n";
64 if (vm.count("debug")) {
65 g.SetDebugMessageLevel(deb);
66 cout << "Debug level is now "<<deb<<"\n";
70 if ( vm.count("print")
79 if (vm.count("print")) {
80 g.GetTreeHandler(handler)->LoadChildren(0,0);
83 if (vm.count("file")) {
84 std::vector<std::string> files=vm["file"].as< vector<string> >();
85 g.AddFiles(handler,files);
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"));
91 if (vm.count("sync")) {
92 g.Synchronize(true,g.GetTreeHandler(handler));
96 catch (crea::Exception e)