Public Member Functions

Dedupe::CLI::Cli Class Reference

#include <cli.h>

Public Member Functions

 Cli (int ac, char *av[], Dedupe::Core::Kernel &RunningKernel, std::ostream &Message)
void Run ()

Detailed Description

Cli class controlls the start parameters of dedupe

Definition at line 28 of file cli.h.


Constructor & Destructor Documentation

Dedupe::CLI::Cli::Cli ( int  ac,
char *  av[],
Dedupe::Core::Kernel RunningKernel,
std::ostream &  Message 
)

Give the main arguments to the Cli, also a reference to the running Kernel class, cause Cli calls it's functions.Also specify which ofstream object should be used for the output to the user

Definition at line 13 of file cli.cpp.

:Kernel( RunningKernel ),
  MessageOut( Message ),
   OpDesc( "Program Options" ),
   VarMap( ),
   Recursive( false ),
   SupressUpdate( false ),
   AddValues( ),
   DelValues( ),
   DupByHash(),
   DupByFilename(),
   DupByFilesize(),
   DupByFiledate(),
   Outputfile( "" ),
   Inputfile( "")
{
  //Generate the general options of the program
  bpo::options_description General( "General Options");
  General.add_options()
     ( "help,h", "Show the help text")
     ( "version,V", "Show program version")
     ( "verbose,v", "Enable verbose mode(NOT IMPLEMENTED)")
     ( "no-dbs-update,s",
          "Disable automatic update of database on programcall");


  //Generate the operating options for the program
  bpo::options_description Operating( "Operation Options");
  Operating.add_options()
     //all given paths from add are stored in AddValues
     ( "track,t",
        bpo::value<Dedupe::FilePaths>( &AddValues ),
       "Add a file to the tracked files")

     ( "list,l", "List all files that are stored in the database" )

     ( "untrack,d",
        bpo::value<Dedupe::FilePaths>( &DelValues ),
       "Delete a file from the tracked files")

     ( "find-hash-duplicates,H",
       bpo::value<Dedupe::FilePaths>( &DupByHash )->multitoken()->zero_tokens(),
       "Find duplicates by hash and start userinterface. If you give a path,\
       duplicates are searched directly in the directories without database")

     ( "find-filename-duplicates,F",
       bpo::value<Dedupe::FilePaths>( &DupByFilename )->multitoken()->zero_tokens(),
       "Find duplicates by filename and start userinterface. If you give a path,\
      duplicates are searched directly in the directories without database")

     ( "find-filesize-duplicates,S",
       bpo::value<Dedupe::FilePaths>( &DupByFilesize )->multitoken()->zero_tokens(),
       "Find duplicates by filesize and start userinterface. If you give a path,\
      duplicates are searched directly in the directories without database")

     ( "find-filedate-duplicates,D",
       bpo::value<Dedupe::FilePaths>( &DupByFiledate)->multitoken()->zero_tokens(),
       "Find duplicates by filedate and start userinterface. If you give a path,\
      duplicates are searched directly in the directories without database")

      //TODO Make positional
      ( "output-file,o",
        bpo::value<Dedupe::FilePath>( &Outputfile ),
        "Set Outputfile" )

      ("process-duplicates,p", bpo::value<Dedupe::FilePath>(&Inputfile ),
        "Give File with decided Duplicates back to process them ")

     ( "update-database,u", "Update the database manually")

     ( "recursive,r", "Enable recursive");

   /*add is positional that means a call like "program /path" is the same as
      "program --add /path   */
   bpo::positional_options_description PosDesc;
   PosDesc.add( "track", -1 );

   //OpDesc is printed by a call to --help, so plug all descriptions together
   OpDesc.add( General ) .add( Operating );

   //We are parsing the commandline
   bpo::store(boost::program_options::command_line_parser( ac, av )
                       .options( OpDesc )
                        .positional( PosDesc )
                         .run() , VarMap );
}


Member Function Documentation

void Dedupe::CLI::Cli::Run (  ) 

Call Run to start the work of Cli

Definition at line 102 of file cli.cpp.

References Dedupe::Core::Kernel::AutoUpdateDatabase(), Dedupe::Core::Kernel::FindFiledateDuplicates(), Dedupe::Core::Kernel::FindFiledateDuplicatesExtern(), Dedupe::Core::Kernel::FindFilenameDuplicates(), Dedupe::Core::Kernel::FindFilenameDuplicatesExtern(), Dedupe::Core::Kernel::FindFilesizeDuplicates(), Dedupe::Core::Kernel::FindFilesizeDuplicatesExtern(), Dedupe::Core::Kernel::FindHashDuplicates(), Dedupe::Core::Kernel::FindHashDuplicatesExtern(), Dedupe::Core::Kernel::ListDatabase(), Dedupe::CLI::UI::ReadDecidedDuplicatesFromFile(), Dedupe::CLI::UI::SetTitle(), Dedupe::Core::Kernel::TrackFiles(), Dedupe::Core::Kernel::UntrackFiles(), and Dedupe::CLI::UI::WriteDuplicatesToFile().

{
   bpo::notify(VarMap);

   if( VarMap.count ( "recursive" ) ) Recursive = true;
   if( VarMap.count( "help" ) ) MessageOut << OpDesc << std::endl;
   if( VarMap.count ( "version" ) ) MessageOut << "ALPHA 4" << std::endl;
   if( VarMap.count ( "no-dbs-update")) SupressUpdate = true;

   if( VarMap.count ("track" ) )
   {
     //Check if database is up to date before add new tracks, but only
     //if the users wish it
     if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
     Kernel.TrackFiles( AddValues, Recursive );
   }

   if( VarMap.count ( "list" ) )
   {
     if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
     Kernel.ListDatabase();
   }

   if( VarMap.count ( "untrack" ) )
   {
     if( !SupressUpdate) Kernel.AutoUpdateDatabase();
     Kernel.UntrackFiles( DelValues, Recursive );
   }

   if( VarMap.count ( "find-hash-duplicates") )
   {
     Dedupe::CLI::UI Userinterface( MessageOut );

     //if paths are given, search in the given directories
     if( DupByHash.size() > 0 )
     {
        Userinterface.SetTitle( "Founded Duplicats by Hash(Extern)" );
        Userinterface.WriteDuplicatesToFile(
        Kernel.FindHashDuplicatesExtern( DupByHash, Recursive ),
        Outputfile );
     }
     //else search in the database
     else
     {
       if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
       Userinterface.SetTitle( "Founded Duplicats by Hash(Intern)" );
       Userinterface.WriteDuplicatesToFile(
        Kernel.FindHashDuplicates(), Outputfile );
     }
   }

   if( VarMap.count( "find-filename-duplicates" ))
   {
     Dedupe::CLI::UI Userinterface( MessageOut );

     //if paths are given, search in the given directories
     if( DupByFilename.size() > 0 )
     {
        Userinterface.SetTitle( "Founded Duplicats by Filename(Extern)" );
        Userinterface.WriteDuplicatesToFile(
        Kernel.FindFilenameDuplicatesExtern( DupByFilename, Recursive ),
        Outputfile );
     }
     //else search in the database
     else
     {
       if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
       Userinterface.SetTitle( "Founded Duplicats by Filename(Intern)" );
       Userinterface.WriteDuplicatesToFile(
        Kernel.FindFilenameDuplicates(), Outputfile );
     }
   }

   if( VarMap.count( "find-filesize-duplicates" ))
   {
     Dedupe::CLI::UI Userinterface( MessageOut );

     //if paths are given, search in the given directories
     if( DupByFilesize.size() > 0 )
     {
        Userinterface.SetTitle( "Founded Duplicats by Filesize(Extern)" );
        Userinterface.WriteDuplicatesToFile(
        Kernel.FindFilesizeDuplicatesExtern( DupByFilesize, Recursive ),
        Outputfile );
     }
     //else search in the database
     else
     {
       if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
       Userinterface.SetTitle( "Founded Duplicats by Filesize(Intern)" );
       Userinterface.WriteDuplicatesToFile(
        Kernel.FindFilesizeDuplicates(), Outputfile );
     }
   }

   if( VarMap.count( "find-filedate-duplicates" ))
   {
     Dedupe::CLI::UI Userinterface( MessageOut );

     //if paths are given, search in the given directories
     if( DupByFiledate.size() > 0 )
     {
        Userinterface.SetTitle( "Founded Duplicats by Filedate(Extern)" );
        Userinterface.WriteDuplicatesToFile(
        Kernel.FindFiledateDuplicatesExtern( DupByFiledate, Recursive ),
        Outputfile );
     }
     //else search in the database
     else
     {
       if( !SupressUpdate ) Kernel.AutoUpdateDatabase();
       Userinterface.SetTitle( "Founded Duplicats by Filedate(Intern)" );
       Userinterface.WriteDuplicatesToFile(
        Kernel.FindFiledateDuplicates(), Outputfile );
     }
   }

   if( VarMap.count( "process-duplicates"))
   {
     Dedupe::CLI::UI Userinterface( MessageOut );
     Userinterface.ReadDecidedDuplicatesFromFile( Inputfile );
   }

   if( VarMap.count( "update-database") ) Kernel.AutoUpdateDatabase();
}


The documentation for this class was generated from the following files: