X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fgimmick%2Fmain.cxx;h=f5f1c1ce7b1250c7a92a153ec30bff5de055d6de;hb=7a7557d18e0cd9551a5d0abc3de53e811f11f76e;hp=397a4f9f6670a7c84d06b4f9b8b71ff8d5b79305;hpb=bfede4f2084492a14d5d7c68f7d1a60d91865236;p=creaImageIO.git diff --git a/appli/gimmick/main.cxx b/appli/gimmick/main.cxx index 397a4f9..f5f1c1c 100644 --- a/appli/gimmick/main.cxx +++ b/appli/gimmick/main.cxx @@ -1,55 +1,153 @@ +/* + # --------------------------------------------------------------------- + # + # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image + # pour la Santé) + # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton + # Previous Authors : Laurent Guigues, Jean-Pierre Roux + # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil + # + # This software is governed by the CeCILL-B license under French law and + # abiding by the rules of distribution of free software. You can use, + # modify and/ or redistribute the software under the terms of the CeCILL-B + # license as circulated by CEA, CNRS and INRIA at the following URL + # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + # or in the file LICENSE.txt. + # + # As a counterpart to the access to the source code and rights to copy, + # modify and redistribute granted by the license, users are provided only + # with a limited warranty and the software's author, the holder of the + # economic rights, and the successive licensors have only limited + # liability. + # + # The fact that you are presently reading this means that you have had + # knowledge of the CeCILL-B license and that you accept its terms. + # ------------------------------------------------------------------------ +*/ +#include + +using namespace boost; +namespace po = boost::program_options; + #include #include -#include -int main(int argc, char* argv[]) +using namespace std; + +int main(int ac, char* av[]) { - gengetopt_args_info args; - if (cmdline_parser (argc, argv, &args) != 0) return 0 ; - + creaImageIO::Gimmick g; - if (args.verbose_given) g.SetMessageLevel(args.verbose_arg); - if (args.debug_given) g.SetDebugMessageLevel(args.debug_arg); - - bool something_to_do = - args.dir_given | - args.file_given | - args.print_given; + 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"); - if (!something_to_do) - { - std::cout << "Nothing to do !" << std::endl; - return 0; - } + //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 "< files; - // TO DO : multiple files given - files.push_back(args.file_arg); + try + { + g.Initialize(); + if (vm.count("print")) { + g.GetTreeHandler(handler)->LoadChildren(0,0); + g.Print(handler); + } + if (vm.count("file")) { + std::vector files=vm["file"].as< vector >(); g.AddFiles(handler,files); } - if (args.dir_given) - { - g.AddDir(handler,args.dir_arg, args.recurse_given); + if (vm.count("dir")) { + std::vector dirs=vm["dir"].as< vector >(); + bool recu=false; + std::stringstream out; + out<LoadChildren(0,0); - g.Print(handler); + if (vm.count("sync")) { + bool rep=false; + bool chk=false; + std::vector 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(); - } + g.Finalize(); + } + catch (crea::Exception e) + { + e.Print(); + } + } + + return 0; }