]>
Commit | Line | Data |
---|---|---|
5f81d796 RBR |
1 | use std::fs; |
2 | use std::path::PathBuf; | |
3 | use crate::configuration::Configuration; | |
4 | ||
a9c6be41 | 5 | pub 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 | 21 | fn 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 | } |