]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4447: main: change help command to print in alphabetical order.
authorMaksym Mykhailov -X (mmykhail - SOFTSERVE INC at Cisco) <mmykhail@cisco.com>
Mon, 30 Sep 2024 19:26:04 +0000 (19:26 +0000)
committerSteve Chew (stechew) <stechew@cisco.com>
Mon, 30 Sep 2024 19:26:04 +0000 (19:26 +0000)
Merge in SNORT/snort3 from ~MMYKHAIL/snort3:help_commands to master

Squashed commit of the following:

commit 8a8144228ce38a2395be33cf5509b6a2847aeae9
Author: Maksym Mykhailov <mmykhail@cisco.com>
Date:   Thu Sep 12 09:31:58 2024 -0400

    main: change help command to print in alphabetical order.

src/main.cc

index 86c059c50d38616a039644d2b36774633266881c..b6b03373a3cfee6a1e23bd73e1e4872bb00a117b 100644 (file)
@@ -816,6 +816,9 @@ int main_help(lua_State* L)
 {
     ControlConn* ctrlcon = ControlConn::query_from_lua(L);
     std::list<Module*> modules = ModuleManager::get_all_modules();
+    std::set<std::string> no_prefix_cmds;
+    std::set<std::string> prefix_cmds;
+
     for (const auto& m : modules)
     {
         const Command* cmd = m->get_commands();
@@ -835,10 +838,22 @@ int main_help(lua_State* L)
             info += ": ";
             info += cmd->help;
             info += "\n";
-            send_response(ctrlcon, info.c_str());
+            if (prefix.empty())
+                no_prefix_cmds.emplace(info);
+            else
+                prefix_cmds.emplace(info);
             ++cmd;
         }
     }
+    
+    send_response(ctrlcon, "\nModule Commands:\n");
+    for (const auto& str : prefix_cmds)
+        send_response(ctrlcon, str.c_str());
+
+    send_response(ctrlcon, "\nTop Level Commands:\n");
+    for (const auto& str : no_prefix_cmds)
+        send_response(ctrlcon, str.c_str());
+    
     return 0;
 }