svenstaro / genact

🌀 A nonsense activity generator
https://svenstaro.github.io/genact/
MIT License
9.66k stars 416 forks source link

Module list (`genact --help` & `genact --list-modules`) is unordered. #527

Closed VergeDX closed 1 year ago

VergeDX commented 1 year ago

As the title says, module list output of genact --help or genact --list-modules is unordered,
will change of each run. Also, I noticed the random module choice does not rely on HashMap's randomness.

VergeDX commented 1 year ago
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index 664e710..aca3109 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -18,7 +18,7 @@ pub mod simcity;
 pub mod weblog;

 use async_trait::async_trait;
-use std::collections::HashMap;
+use std::collections::BTreeMap;

 use crate::args::AppConfig;

@@ -30,8 +30,8 @@ pub trait Module: Sync {
 }

 lazy_static::lazy_static! {
-    pub static ref ALL_MODULES: HashMap<&'static str, Box<dyn Module>> = {
-        let mut all_modules: HashMap<&'static str, Box<dyn Module>> = HashMap::new();
+    pub static ref ALL_MODULES: BTreeMap<&'static str, Box<dyn Module>> = {
+        let mut all_modules: BTreeMap<&'static str, Box<dyn Module>> = BTreeMap::new();
         all_modules.insert("ansible", Box::new(ansible::Ansible));
         all_modules.insert("bootlog", Box::new(bootlog::Bootlog));
         all_modules.insert("botnet", Box::new(botnet::Botnet));
svenstaro commented 1 year ago

Oh wow, never noticed! Wanna make a quick PR?