X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fgimmick%2Fmain.cxx;h=b064a25829d19c22f0706e81a9681f42ddff3e6d;hb=7e532afa6e1ab955d7c0fa63ea5d12eabc2504e5;hp=d90f0b8bcfa15f955261f571e2bef05c284c78d1;hpb=bae4df8a3e1ea669400c3a6c44ef4aa8d90fa1ed;p=creaImageIO.git diff --git a/appli/gimmick/main.cxx b/appli/gimmick/main.cxx index d90f0b8..b064a25 100644 --- a/appli/gimmick/main.cxx +++ b/appli/gimmick/main.cxx @@ -1,18 +1,127 @@ +#include + +using namespace boost; +namespace po = boost::program_options; + #include #include -int main(int argc, char* argv[]) -{ - bool debug = false; - if(argc>1) - { - debug = true; - } +using namespace std; +int main(int ac, char* av[]) +{ + creaImageIO::Gimmick g; - g.SetDebugMode(debug); + int verb,deb; + std::string handler("Local database"); + + //Describes first group of options + po::options_description generic("GENERIC"); + generic.add_options() + ("help,h", "Print help and exit") + ("version,V", "Print version and exit"); + + //Describes second group of options + po::options_description command("COMMANDS"); + command.add_options() + ("print,p","Prints the local database tree (default=off)") + ("files,f",po::value< vector >(),"Adds the file(s) to the local database") + ("dir,d",po::value< vector >(),"Adds the directory to the local database") + ("sync,s",po::value< vector >(),"Synchronizes the local database with the files") + ("copy,c",po::value< vector >(),"Copies the files into a local directory"); + + //Describes third group of options + po::options_description option("OPTIONS"); + option.add_options() + ("verbose,v",po::value(&verb),"Verbosity level (default=`1')") + ("debug,D",po::value(&deb),"Debug messages level (default=`0')") + ("recurse,r","Recurse into sub-directories (default=off)") + ("repair,R","Repair the database (on synchronization) (default=off)") + ("check,C","Check for attribute differences (on synchronization) (default=off)") + ("handler,H",po::value(&handler),"Handler name (default=`Local database')"); + + //Adds the groups into a big one + po::options_description cmdline_options; + cmdline_options.add(generic).add(command).add(option); + + //Adds the corresponding variables + po::variables_map vm; + po::store(po::parse_command_line(ac, av, cmdline_options), vm); + po::notify(vm); + + + //Does something on each option + //GENERIC + if (vm.count("help")) { + cout << "Usage: gimmick COMMAND [OPTIONS]:\n"; + cout << cmdline_options << "\n"; + } + if (vm.count("version")) { + cout << "gimmick 0.1.0\n"; + } + + //OPTIONS + if (vm.count("verbose")) { + g.SetMessageLevel(verb); + cout << "Verbose level is now "<LoadChildren(0,0); + g.Print(handler); + } + if (vm.count("file")) { + std::vector files=vm["file"].as< vector >(); + g.AddFiles(handler,files); + } + if (vm.count("dir")) { + std::vector dirs=vm["dir"].as< vector >(); + bool recu=false; + std::stringstream out; + out< name=vm["sync"].as< vector >(); + std::stringstream out; + out< name=vm["copy"].as< vector >(); + g.CopyFiles(name,handler); + } + g.Finalize(); + } + catch (crea::Exception e) + { + e.Print(); + } + } + + return 0; }