]> git.r.bdr.sh - rbdr/blog/blob - src/command/status/configuration_status.rs
Add mac
[rbdr/blog] / src / command / status / configuration_status.rs
1 use std::fs;
2 use std::path::PathBuf;
3 use crate::configuration::Configuration;
4
5 pub fn status(configuration: &Configuration) -> String {
6 let mut status_message = String::new();
7
8 status_message.push_str("# Configuration\n");
9 status_message.push_str("\n## Directories\n");
10
11 // Main Configuration Locations
12 status_message.push_str(&get_directory_stats("Configuration", &configuration.config_directory));
13 status_message.push_str(&get_directory_stats("Data", &configuration.data_directory));
14 status_message.push_str(&get_directory_stats("Output", &configuration.output_directory));
15
16 status_message.push_str("\n## Blog Settings\n");
17 status_message.push_str(&format!("Number of posts to keep: {}\n", configuration.max_posts));
18 status_message
19 }
20
21 fn get_directory_stats(label: &str, directory: &PathBuf) -> String {
22 let mut status_message = String::new();
23
24 status_message.push_str(&format!("{}: {}. ", label, directory.display()));
25 if directory.exists() {
26 status_message.push_str("Exists ");
27 if fs::read_dir(&directory).is_ok() {
28 status_message.push_str("and is readable.\n");
29 } else {
30 status_message.push_str("but is not readable.\n");
31 }
32 } else {
33 status_message.push_str("Does not exist.\n");
34 }
35
36 status_message
37 }