]> Creatis software - creaImageIO.git/blobdiff - appli/gimmick/main.cxx
*** empty log message ***
[creaImageIO.git] / appli / gimmick / main.cxx
index 3e13d8e101b073c1d4a5c3ac91f25137ce67290b..bee8ff1c269aa6b2137bbd82c9d695eaa1854764 100644 (file)
+#include <boost/program_options.hpp>
+using namespace boost;
+namespace po = boost::program_options;
+
 #include <creaImageIOGimmick.h>
 #include <creaMessageManager.h>
-#include <gimmick_ggo.h>
 
-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) exit(1) ;
-     
+  
   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;
-
-  if (!something_to_do)
-    {
-      std::cout << "Nothing to do !" << std::endl;
-      exit(0);
-    }
-
+  int verb,deb;
   std::string handler("Local database");
-  try
-    {
-      g.Initialize();
-      
-      if (args.file_given) 
-       {
-         g.AddFile(handler,args.file_arg);
-       }
-      if (args.dir_given) 
-       {
-         g.AddDir(handler,args.dir_arg, args.recurse_given);
-       }
-      
-      if (args.print_given) 
-       {
+  
+  //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)")
+    ("file,f",po::value< vector<string> >(),"Adds the file to the local database")
+    ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
+    ("sync,s","Synchronizes the local database with the files")
+    ("recurse,r","Recurse into sub-directories  (default=off)");
+  
+  //Describes third group of options
+  po::options_description option("OPTIONS");
+  option.add_options()
+    ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
+    ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')");
+  
+  
+  //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 "<<verb<<"\n";
+  }
+  if (vm.count("debug")) {
+    g.SetDebugMessageLevel(deb);
+    cout << "Debug level is now "<<deb<<"\n";
+  }
+  
+  //COMMANDS
+  if (  vm.count("print")
+       ||vm.count("file")
+       ||vm.count("dir")
+       ||vm.count("sync")
+       )
+
+    try
+      {
+       g.Initialize();
+       if (vm.count("print")) {
          g.GetTreeHandler(handler)->LoadChildren(0,0);
          g.Print(handler);
        }
-      
-      g.Finalize();
-    }
-  catch (crea::Exception e)
-    {
-      e.Print();
-    }
+       if (vm.count("file")) {
+         std::vector<std::string> files=vm["file"].as< vector<string> >();
+         g.AddFiles(handler,files);
+       }
+       if (vm.count("dir")) {
+         std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
+         g.AddDir(handler,dirs.front(), vm.count("recurse"));
+       }
+       if (vm.count("sync")) {
+         g.Synchronize(true,g.GetTreeHandler(handler));
+       }       
+       g.Finalize();
+      }
+    catch (crea::Exception e)
+      {
+       e.Print();
+      }
+  
   return 0;
 }