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