Browse Source

autoformat

Denys 4 years ago
parent
commit
cdce834ae2
5 changed files with 74 additions and 61 deletions
  1. 4 3
      cli/include/cmdman.h
  2. 4 3
      cli/include/ioman.h
  3. 59 51
      cli/src/cmdman.cpp
  4. 3 2
      cli/src/ioman.cpp
  5. 4 2
      cli/src/userioman.cpp

+ 4 - 3
cli/include/cmdman.h

@@ -93,8 +93,9 @@ private:
   map<string, string> helpmap;
 
   /**
-   * State used to internally format received json to allow easy handling using 
-   * handlemap and to disallow the use of certain commands when logged in/not logged in.
+   * State used to internally format received json to allow easy handling using
+   * handlemap and to disallow the use of certain commands when logged in/not
+   * logged in.
    */
   bool doversion, loginpossible, dologin, dosignup;
 
@@ -114,7 +115,7 @@ private:
   CmdRet cmdGet(vector<string> args);
   const string descList = "list files available on server";
   CmdRet cmdList(vector<string> args);
-  
+
   const string descLogin = "login to the server";
   CmdRet cmdLogin(vector<string> args);
   const string descSignup = "sign up and login to the server";

+ 4 - 3
cli/include/ioman.h

@@ -122,9 +122,10 @@ protected:
    */
   virtual void printWelcomeMessage() = 0;
   virtual std::string getCmdPrompt() = 0;
-  // following prompts currently not in use because login happens by entering command
-//~  virtual std::string getUserPrompt() = 0;
-//~  virtual std::string getPassPrompt() = 0;
+  // following prompts currently not in use because login happens by entering
+  // command
+  //~  virtual std::string getUserPrompt() = 0;
+  //~  virtual std::string getPassPrompt() = 0;
 
 public:
   /**

+ 59 - 51
cli/src/cmdman.cpp

@@ -14,7 +14,6 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
   wbuilder.settings_["indentation"] = "";
   reader = rbuilder.newCharReader();
 
-  
   doversion = false;
   loginpossible = false;
   dologin = false;
@@ -89,16 +88,15 @@ CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
   DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
   Json::Value root;
   retval.type = send;
-  if(loginpossible) {
-	  // not logged in, send appropriate login message instead of normal close
-	  root["login"] = false;
-	  root["user"] = "";
-	  root["pass"] = "";
-	  root["cancel"] = true;
-	  retval.type |= close;
-  }
-  else {
-	root["command"] = "close";
+  if (loginpossible) {
+    // not logged in, send appropriate login message instead of normal close
+    root["login"] = false;
+    root["user"] = "";
+    root["pass"] = "";
+    root["cancel"] = true;
+    retval.type |= close;
+  } else {
+    root["command"] = "close";
   }
   retval.msg = root;
 
@@ -226,22 +224,29 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
   Json::Value root;
   root["command"] = cmd;
   if (it == execmap.end()) {
-	  retval.type = error;
-	  root["command"] = "error";
-	  root["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd + "\".\ntype help to list available commands.";
-	  retval.msg = root;
-	  return retval;
-  }
-  else if(loginpossible || dologin || dosignup) {
-	  DEBUGPRINT("execute does login");
-	  DEBUGPRINT(string("comparison is ") + std::to_string(cmd.compare("login") && cmd.compare("signup") && cmd.compare("disconnect") && cmd.compare("help")));
-	  if(cmd.compare("login") && cmd.compare("signup") && cmd.compare("disconnect") && cmd.compare("help")) {
-		  retval.type = error;
-		  root["command"] = "error";
-		  root["error"] = string("Not logged in. Available commands are limited to ") + "login" + ", " + "signup" + " and " + "disconnect" + "\n" + "Use help for usage of these commands.";
-		  retval.msg = root;
-		  return retval;
-	  }
+    retval.type = error;
+    root["command"] = "error";
+    root["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd +
+                    "\".\ntype help to list available commands.";
+    retval.msg = root;
+    return retval;
+  } else if (loginpossible || dologin || dosignup) {
+    DEBUGPRINT("execute does login");
+    DEBUGPRINT(string("comparison is ") +
+               std::to_string(cmd.compare("login") && cmd.compare("signup") &&
+                              cmd.compare("disconnect") &&
+                              cmd.compare("help")));
+    if (cmd.compare("login") && cmd.compare("signup") &&
+        cmd.compare("disconnect") && cmd.compare("help")) {
+      retval.type = error;
+      root["command"] = "error";
+      root["error"] =
+          string("Not logged in. Available commands are limited to ") +
+          "login" + ", " + "signup" + " and " + "disconnect" + "\n" +
+          "Use help for usage of these commands.";
+      retval.msg = root;
+      return retval;
+    }
   }
   return (this->*(execmap[cmd]))(args);
 }
@@ -251,8 +256,8 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
   CmdRet retval;
   DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
   Json::Value root;
-  
-  if(loginpossible) { 
+
+  if (loginpossible) {
     dologin = true;
     loginpossible = false;
     root["user"] = args[0];
@@ -262,11 +267,12 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
     retval.type = send;
   } else {
     root["command"] = "login";
-    root["error"] = "Login not possible, because you already requested a login or you are logged in";
+    root["error"] = "Login not possible, because you already requested a login "
+                    "or you are logged in";
     root["accept"] = false;
-	retval.type = error;
+    retval.type = error;
   }
-  
+
   retval.msg = root;
   return retval;
 }
@@ -275,10 +281,10 @@ CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
   CmdRet retval;
   DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
   Json::Value root;
-  
-  if(loginpossible) { 
+
+  if (loginpossible) {
     dosignup = true;
-	loginpossible = false;
+    loginpossible = false;
     root["user"] = args[0];
     root["pass"] = args[1];
     root["login"] = true;
@@ -286,16 +292,16 @@ CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
     retval.type = send;
   } else {
     root["command"] = "signup";
-    root["error"] = "Signup not possible, because you already requested a login or you are logged in";
+    root["error"] = "Signup not possible, because you already requested a "
+                    "login or you are logged in";
     root["accept"] = false;
-	retval.type = error;
+    retval.type = error;
   }
-  
+
   retval.msg = root;
   return retval;
 }
 
-
 /* internal commands */
 CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
   CmdRet retval;
@@ -311,12 +317,12 @@ CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
 }
 
 CmdMan::CmdRet CmdMan::handle(Json::Value root) {
-	CmdRet retval;
-	Json::Value output;
+  CmdRet retval;
+  Json::Value output;
   DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
   if (doversion)
     root["command"] = "version";
-  else if (dosignup) 
+  else if (dosignup)
     root["command"] = "signup";
   else if (dologin)
     root["command"] = "login";
@@ -325,13 +331,15 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
   string retmsg;
   map<string, CmdRet (CmdMan::*)(Json::Value)>::iterator it =
       handlemap.find(root["command"].asString());
-  
+
   if (it == handlemap.end()) {
-	  retval.type = error;
-	  output["command"] = "error";
-	  output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString() + "\".\nEnsure code is implemented.";
-	  retval.msg = output;
-	  return retval;
+    retval.type = error;
+    output["command"] = "error";
+    output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" +
+                      root["command"].asString() +
+                      "\".\nEnsure code is implemented.";
+    retval.msg = output;
+    return retval;
   }
   return (this->*(handlemap[root["command"].asString()]))(root);
 }
@@ -603,7 +611,7 @@ CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
     retval.type = error;
     output["error"] = root["error"].asString();
     output["accept"] = false;
-	loginpossible = true;
+    loginpossible = true;
     dologin = false;
   } else {
     retval.type = print | seton;
@@ -627,13 +635,13 @@ CmdMan::CmdRet CmdMan::handleSignup(Json::Value root) {
     retval.type = error;
     output["error"] = root["error"].asString();
     output["accept"] = false;
-	loginpossible = true;
+    loginpossible = true;
     dosignup = false;
   } else {
     retval.type = print | seton;
     output["error"] = "";
     output["accept"] = true;
-	dosignup = false;
+    dosignup = false;
   }
   retval.msg = output;
 

+ 3 - 2
cli/src/ioman.cpp

@@ -376,7 +376,7 @@ void IoMan::inputMain() {
       if (cmdret.type & CmdMan::rettype::error) {
         printMessage(Json::writeString(wbuilder, cmdret.msg), error);
       }
-      if(cmdret.type & CmdMan::rettype::close) {
+      if (cmdret.type & CmdMan::rettype::close) {
         /* TODO i dunno */
         mainmutex.lock();
         runmain = false;
@@ -546,7 +546,8 @@ void IoMan::run() {
     }
     if (!connected)
       break;
-    if(loginstatus == err) break;
+    if (loginstatus == err)
+      break;
     mainmutex.lock();
   }
   mainmutex.unlock();

+ 4 - 2
cli/src/userioman.cpp

@@ -66,7 +66,9 @@ void UserIoMan::printMessage(std::string msg, OutMsgType type) {
 }
 
 void UserIoMan::printWelcomeMessage() {
-  std::cout << "please login by entering \"login <username> <password>\" \nor sign up and log in with \"signup <username> <password>\"" << std::endl;
+  std::cout << "please login by entering \"login <username> <password>\" \nor "
+               "sign up and log in with \"signup <username> <password>\""
+            << std::endl;
 }
 
 std::string UserIoMan::getCmdPrompt() { return "ccats> "; }
@@ -90,7 +92,7 @@ void UserIoMan::printJson(Json::Value root) {
 }
 
 void UserIoMan::printError(Json::Value root) {
-    std::cout << "Error: " << root["error"].asString() << std::endl;
+  std::cout << "Error: " << root["error"].asString() << std::endl;
 }
 
 void UserIoMan::printConnect(Json::Value root) {