Commits

Kimmo Varis committed ef3c2db

CLI: Check that given paths exist.

  • Participants
  • Parent commits b930c59

Comments (0)

Files changed (2)

File cli/process.cpp

 #include <QString>
 #include <QStringList>
 #include <QCoreApplication>
+#include <QTextStream>
+#include <QDir>
 #include "process.h"
 #include "analyzer.h"
 
 void Process::check()
 {
+    if (!parseCmdLine())
+        return;
+
+    Analyzer analyzer(mDir1, mDir2);
+}
+
+bool Process::parseCmdLine()
+{
+    QTextStream qOut(stdout);
     QStringList args = QCoreApplication::arguments();
     //Remove the application itself
     args.removeFirst();
 
-    Analyzer analyzer(args[0], args[1]);
+    if (args.size() != 2)
+    {
+        qOut << "Give two directories as parameters." << endl;
+        return false;
+    }
+
+    mDir1 = args[0];
+    mDir2 = args[1];
+
+    QDir dir1(mDir1);
+    if (!dir1.exists())
+    {
+        qOut << "Directory '" << mDir1 << "' could not be found!" << endl;
+        return false;
+    }
+    QDir dir2(mDir2);
+    if (!dir2.exists())
+    {
+        qOut << "Directory '" << mDir2 << "' could not be found!" << endl;
+        return false;
+    }
+    return true;
 }

File cli/process.h

 #ifndef PROCESS_H
 #define PROCESS_H
 
+#include <QString>
+
 class Process
 {
 public:
     void check();
+
+protected:
+    bool parseCmdLine();
+
+private:
+    QString mDir1;
+    QString mDir2;
 };
 
 #endif // PROCESS_H