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