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 ("recurse,r","Recurse into sub-directories (default=off)");
32 //Describes third group of options
33 po::options_description option("OPTIONS");
35 ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
36 ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')");
39 //Adds the groups into a big one
40 po::options_description cmdline_options;
41 cmdline_options.add(generic).add(command).add(option);
43 //Adds the corresponding variables
45 po::store(po::parse_command_line(ac, av, cmdline_options), vm);
48 //Does something on each option
50 if (vm.count("help")) {
51 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
52 cout << cmdline_options << "\n";
54 if (vm.count("version")) {
55 cout << "gimmick 0.1.0\n";
59 if (vm.count("verbose")) {
60 g.SetMessageLevel(verb);
61 cout << "Verbose level is now "<<verb<<"\n";
63 if (vm.count("debug")) {
64 g.SetDebugMessageLevel(deb);
65 cout << "Debug level is now "<<deb<<"\n";
69 if(vm.count("print")||vm.count("file")||vm.count("dir"))
73 if (vm.count("print")) {
74 g.GetTreeHandler(handler)->LoadChildren(0,0);
77 if (vm.count("file")) {
78 std::vector<std::string> files=vm["file"].as< vector<string> >();
79 g.AddFiles(handler,files);
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"));
87 catch (crea::Exception e)