]>
Commit | Line | Data |
---|---|---|
d7fef30a | 1 | use crate::configuration::Configuration; |
5f81d796 RBR |
2 | use std::fs; |
3 | use std::path::PathBuf; | |
5f81d796 | 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 | |
d7fef30a RBR |
12 | status_message.push_str(&get_directory_stats( |
13 | "Configuration", | |
14 | &configuration.config_directory, | |
15 | )); | |
a9c6be41 | 16 | status_message.push_str(&get_directory_stats("Data", &configuration.data_directory)); |
d7fef30a RBR |
17 | status_message.push_str(&get_directory_stats( |
18 | "Output", | |
19 | &configuration.output_directory, | |
20 | )); | |
5f81d796 | 21 | |
a9c6be41 | 22 | status_message.push_str("\n## Blog Settings\n"); |
d7fef30a RBR |
23 | status_message.push_str(&format!( |
24 | "Number of posts to keep: {}\n", | |
25 | configuration.max_posts | |
26 | )); | |
5f81d796 RBR |
27 | status_message |
28 | } | |
29 | ||
a9c6be41 | 30 | fn get_directory_stats(label: &str, directory: &PathBuf) -> String { |
5f81d796 RBR |
31 | let mut status_message = String::new(); |
32 | ||
a9c6be41 | 33 | status_message.push_str(&format!("{}: {}. ", label, directory.display())); |
5f81d796 | 34 | if directory.exists() { |
a9c6be41 | 35 | status_message.push_str("Exists "); |
d7fef30a | 36 | if fs::read_dir(directory).is_ok() { |
a9c6be41 | 37 | status_message.push_str("and is readable.\n"); |
5f81d796 | 38 | } else { |
a9c6be41 | 39 | status_message.push_str("but is not readable.\n"); |
5f81d796 RBR |
40 | } |
41 | } else { | |
a9c6be41 | 42 | status_message.push_str("Does not exist.\n"); |
5f81d796 RBR |
43 | } |
44 | ||
45 | status_message | |
46 | } |