]> git.r.bdr.sh - rbdr/blog/blobdiff - src/command/status/configuration_status.rs
Add release
[rbdr/blog] / src / command / status / configuration_status.rs
index 67bf277dcc9d4a38c43d6122a52a45926b0f794c..6d4e56a817c008ebf838ea47bb08915ee15b2f1b 100644 (file)
@@ -2,36 +2,35 @@ use std::fs;
 use std::path::PathBuf;
 use crate::configuration::Configuration;
 
-pub fn status() -> String {
-    let configuration = Configuration::new();
+pub fn status(configuration: &Configuration) -> String {
     let mut status_message = String::new();
 
     status_message.push_str("# Configuration\n");
-    status_message.push_str("## Directories\n");
+    status_message.push_str("\n## Directories\n");
 
     // Main Configuration Locations
-    status_message.push_str(&get_directory_stats("Configuration", configuration.config_directory));
-    status_message.push_str(&get_directory_stats("Data", configuration.data_directory));
-    status_message.push_str(&get_directory_stats("Output", configuration.output_directory));
+    status_message.push_str(&get_directory_stats("Configuration", &configuration.config_directory));
+    status_message.push_str(&get_directory_stats("Data", &configuration.data_directory));
+    status_message.push_str(&get_directory_stats("Output", &configuration.output_directory));
 
-    status_message.push_str("## Blog Settings\n");
+    status_message.push_str("\n## Blog Settings\n");
     status_message.push_str(&format!("Number of posts to keep: {}\n", configuration.max_posts));
     status_message
 }
 
-fn get_directory_stats(label: &str, directory: PathBuf) -> String {
+fn get_directory_stats(label: &str, directory: &PathBuf) -> String {
     let mut status_message = String::new();
 
-    status_message.push_str(&format!("{}: {}\n", label, directory.display()));
+    status_message.push_str(&format!("{}: {}", label, directory.display()));
     if directory.exists() {
-        status_message.push_str(&format!("{} directory exists.\n", label));
+        status_message.push_str("Exists ");
         if fs::read_dir(&directory).is_ok() {
-            status_message.push_str(&format!("{} directory is readable.\n", label));
+            status_message.push_str("and is readable.\n");
         } else {
-            status_message.push_str(&format!("{} directory is not readable.\n", label));
+            status_message.push_str("but is not readable.\n");
         }
     } else {
-        status_message.push_str(&format!("{} directory does not exist.\n", label));
+        status_message.push_str("Does not exist.\n");
     }
 
     status_message