Browse Source

Support invoke command on launch argument

xcbosa-itx 2 years ago
parent
commit
7916f6c14e

+ 1 - 1
controller/auto-generated/framework7-framework7-bundle.min.css.cpp

@@ -1,5 +1,5 @@
 //
-// Created by xcbosa on 2023-02-07
+// Created by xcbosa on 2023-02-08
 //
 
 #include "../../processor/processor.h"

+ 1 - 1
controller/auto-generated/framework7-framework7-bundle.min.js.cpp

@@ -1,5 +1,5 @@
 //
-// Created by xcbosa on 2023-02-07
+// Created by xcbosa on 2023-02-08
 //
 
 #include "../../processor/processor.h"

+ 1 - 1
controller/auto-generated/index.css.cpp

@@ -1,5 +1,5 @@
 //
-// Created by xcbosa on 2023-02-07
+// Created by xcbosa on 2023-02-08
 //
 
 #include "../../processor/processor.h"

+ 1 - 1
controller/auto-generated/index.js.cpp

@@ -1,5 +1,5 @@
 //
-// Created by xcbosa on 2023-02-07
+// Created by xcbosa on 2023-02-08
 //
 
 #include "../../processor/processor.h"

+ 1 - 1
controller/auto-generated/sha256.js.cpp

@@ -1,5 +1,5 @@
 //
-// Created by xcbosa on 2023-02-07
+// Created by xcbosa on 2023-02-08
 //
 
 #include "../../processor/processor.h"

+ 4 - 0
frp.cpp

@@ -125,7 +125,11 @@ namespace xc::frp {
         }
 
         int getRunningPid() {
+#if __APPLE__
+            ::FILE *psStdoutFd = popen("ps -ef | grep frpc | grep -v grep", "r");
+#elif __linux__
             ::FILE *psStdoutFd = popen("ps -ef --columns 1000 | grep frpc | grep -v grep", "r");
+#endif
             ostringstream oss;
             char buff[1024];
             while (::fgets(buff, sizeof(buff), psStdoutFd)) {

+ 12 - 2
main.cpp

@@ -32,12 +32,23 @@ const static strcmd assign("assign", "assign <UserName> <Profile>", "使用户
 });
 
 int main(int argc, char **argv) {
-    std::cout << "Hello, World!" << std::endl;
+    std::cout << "FRPC WebUI HelloWorld!" << std::endl;
+    CommandLineWorker cmdLine;
 
     conf::getRootDir();
     conf::getUserDataDir();
     conf::getFrpcDir();
 
+    if (argc > 1) {
+        ostringstream cmd;
+        for (int i = 1; i < argc; i++) {
+            cmd << argv[i];
+            cmd << " ";
+        }
+        cmdLine.processCommand(cmd.str());
+        return 0;
+    }
+
     ostringstream oss;
     oss << "ps -ef | grep " << argv[0] << " | grep -v grep";
     ::FILE *psStdoutFd = popen(oss.str().c_str(), "r");
@@ -65,7 +76,6 @@ int main(int argc, char **argv) {
 
     thread([] { frp::frpDaemon(); }).detach();
 
-    CommandLineWorker cmdLine;
     cmdLine.workerLoop();
 
     while (true) {

+ 25 - 21
utils/CommandLine.cpp

@@ -42,6 +42,30 @@ namespace xc {
             }
         }
 
+        void CommandLineWorker::processCommand(string cmd) {
+            auto list = split(cmd, " ");
+            string titleUppercase = uppercase(list[0]);
+            if (titleUppercase == "HELP") {
+                cout << "Frp-WebUI Command List" << endl;
+                for (int i = 0; i < registeredCommandsId; i++) {
+                    cout << registeredCommands[i]->message << " : " << registeredCommands[i]->commandUsage << endl;
+                }
+            } else {
+                bool founded = false;
+                for (int i = 0; i < registeredCommandsId; i++) {
+                    auto command = registeredCommands[i];
+                    if (uppercase(command->commandName) == titleUppercase) {
+                        command->evaluate(cmd);
+                        founded = true;
+                        break;
+                    }
+                }
+                if (!founded) {
+                    cerr << "Command " << list[0] << " not founded, type help to view help." << endl;
+                }
+            }
+        }
+
         void CommandLineWorker::workerLoop() {
             char cinReadBuff[1024];
             while (true) {
@@ -53,27 +77,7 @@ namespace xc {
                 }
                 string str(cinReadBuff);
                 if (str.empty()) continue;
-                auto list = split(str, " ");
-                string titleUppercase = uppercase(list[0]);
-                if (titleUppercase == "HELP") {
-                    cout << "Frp-WebUI Command List" << endl;
-                    for (int i = 0; i < registeredCommandsId; i++) {
-                        cout << registeredCommands[i]->message << " : " << registeredCommands[i]->commandUsage << endl;
-                    }
-                } else {
-                    bool founded = false;
-                    for (int i = 0; i < registeredCommandsId; i++) {
-                        auto command = registeredCommands[i];
-                        if (uppercase(command->commandName) == titleUppercase) {
-                            command->evaluate(str);
-                            founded = true;
-                            break;
-                        }
-                    }
-                    if (!founded) {
-                        cerr << "Command " << list[0] << " not founded, type help to view help." << endl;
-                    }
-                }
+                this->processCommand(str);
                 cin.clear();
                 usleep(1000 * 10);
             }

+ 1 - 0
utils/CommandLine.h

@@ -35,6 +35,7 @@ namespace xc {
         class CommandLineWorker {
         public:
             void workerLoop();
+            void processCommand(string cmd);
         };
 
     } // xc