Browse Source

fix: support additional yaml file extension, clippy

PThorpe92 1 năm trước cách đây
mục cha
commit
72c2c74071
2 tập tin đã thay đổi với 29 bổ sung26 xóa
  1. 12 12
      src/options/config.rs
  2. 17 14
      src/options/theme.rs

+ 12 - 12
src/options/config.rs

@@ -628,43 +628,43 @@ mod tests {
 
 
     #[test]
     #[test]
     fn parse_none_color_from_string() {
     fn parse_none_color_from_string() {
-        ["", "none", "None"].iter().for_each(|case| {
+        for case in &["", "none", "None"] {
             assert_eq!(color_from_str(case), None);
             assert_eq!(color_from_str(case), None);
-        });
+        }
     }
     }
 
 
     #[test]
     #[test]
     fn parse_default_color_from_string() {
     fn parse_default_color_from_string() {
-        ["default", "Default"].iter().for_each(|case| {
+        for case in &["default", "Default"] {
             assert_eq!(color_from_str(case), Some(Color::Default));
             assert_eq!(color_from_str(case), Some(Color::Default));
-        });
+        }
     }
     }
 
 
     #[test]
     #[test]
     fn parse_fixed_color_from_string() {
     fn parse_fixed_color_from_string() {
-        ["black", "Black"].iter().for_each(|case| {
+        for case in &["black", "Black"] {
             assert_eq!(color_from_str(case), Some(Color::Black));
             assert_eq!(color_from_str(case), Some(Color::Black));
-        });
+        }
     }
     }
 
 
     #[test]
     #[test]
     fn parse_long_hex_color_from_string() {
     fn parse_long_hex_color_from_string() {
-        ["#ff00ff", "#FF00FF"].iter().for_each(|case| {
+        for case in &["#ff00ff", "#FF00FF"] {
             assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
             assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
-        });
+        }
     }
     }
 
 
     #[test]
     #[test]
     fn parse_short_hex_color_from_string() {
     fn parse_short_hex_color_from_string() {
-        ["#f0f", "#F0F"].iter().for_each(|case| {
+        for case in ["#f0f", "#F0F"].iter() {
             assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
             assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
-        });
+        }
     }
     }
 
 
     #[test]
     #[test]
     fn parse_color_code_from_string() {
     fn parse_color_code_from_string() {
-        [("10", 10), ("01", 1)].iter().for_each(|(s, c)| {
+        for (s, c) in &[("10", 10), ("01", 1)] {
             assert_eq!(color_from_str(s), Some(Color::Fixed(*c)));
             assert_eq!(color_from_str(s), Some(Color::Fixed(*c)));
-        });
+        }
     }
     }
 }
 }

+ 17 - 14
src/options/theme.rs

@@ -35,23 +35,26 @@ impl Options {
 
 
 impl ThemeConfig {
 impl ThemeConfig {
     fn deduce<V: Vars>(vars: &V) -> Option<Self> {
     fn deduce<V: Vars>(vars: &V) -> Option<Self> {
-        if let Some(path) = vars.get("EZA_CONFIG_DIR") {
-            let path = PathBuf::from(path);
-            let path = path.join("theme.yml");
-            if path.exists() {
-                Some(ThemeConfig::from_path(&path.to_string_lossy()))
-            } else {
-                None
-            }
+        let (base_path, is_default_location) = if let Some(path) = vars.get("EZA_CONFIG_DIR") {
+            (PathBuf::from(path), false)
+        } else if let Some(path) = dirs::config_dir() {
+            (path.join("eza"), true)
         } else {
         } else {
-            let path = dirs::config_dir().unwrap_or_default();
-            let path = path.join("eza").join("theme.yml");
-            if path.exists() {
-                Some(ThemeConfig::default())
+            return None;
+        };
+        let yml_path = base_path.join("theme.yml");
+        if yml_path.exists() {
+            return if is_default_location {
+                Some(ThemeConfig::from_path(&yml_path.to_string_lossy()))
             } else {
             } else {
-                None
-            }
+                Some(ThemeConfig::default())
+            };
+        }
+        let yaml_path = base_path.join("theme.yaml");
+        if yaml_path.exists() {
+            return Some(ThemeConfig::from_path(&yaml_path.to_string_lossy()));
         }
         }
+        None
     }
     }
 }
 }