aboutsummaryrefslogtreecommitdiff
path: root/src/command/status
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-02-24 23:20:14 +0000
committerRuben Beltran del Rio <git@r.bdr.sh>2024-02-24 23:20:14 +0000
commit5f81d796fed4e4efbaf6dbed7d3c69481afddeb3 (patch)
treec99b6232a003f5a04e9ba0624d842aac8ac43462 /src/command/status
parent442ebaf901a8ca686ce769325054e1f393d43b7c (diff)
Add status command
Diffstat (limited to 'src/command/status')
-rw-r--r--src/command/status/configuration_status.rs38
-rw-r--r--src/command/status/mod.rs43
2 files changed, 81 insertions, 0 deletions
diff --git a/src/command/status/configuration_status.rs b/src/command/status/configuration_status.rs
new file mode 100644
index 0000000..67bf277
--- /dev/null
+++ b/src/command/status/configuration_status.rs
@@ -0,0 +1,38 @@
+use std::fs;
+use std::path::PathBuf;
+use crate::configuration::Configuration;
+
+pub fn status() -> String {
+ let configuration = Configuration::new();
+ let mut status_message = String::new();
+
+ status_message.push_str("# Configuration\n");
+ status_message.push_str("## Directories\n");
+
+ // Main Configuration Locations
+ status_message.push_str(&get_directory_stats("Configuration", configuration.config_directory));
+ status_message.push_str(&get_directory_stats("Data", configuration.data_directory));
+ status_message.push_str(&get_directory_stats("Output", configuration.output_directory));
+
+ status_message.push_str("## Blog Settings\n");
+ status_message.push_str(&format!("Number of posts to keep: {}\n", configuration.max_posts));
+ status_message
+}
+
+fn get_directory_stats(label: &str, directory: PathBuf) -> String {
+ let mut status_message = String::new();
+
+ status_message.push_str(&format!("{}: {}\n", label, directory.display()));
+ if directory.exists() {
+ status_message.push_str(&format!("{} directory exists.\n", label));
+ if fs::read_dir(&directory).is_ok() {
+ status_message.push_str(&format!("{} directory is readable.\n", label));
+ } else {
+ status_message.push_str(&format!("{} directory is not readable.\n", label));
+ }
+ } else {
+ status_message.push_str(&format!("{} directory does not exist.\n", label));
+ }
+
+ status_message
+}
diff --git a/src/command/status/mod.rs b/src/command/status/mod.rs
new file mode 100644
index 0000000..ba73184
--- /dev/null
+++ b/src/command/status/mod.rs
@@ -0,0 +1,43 @@
+mod configuration_status;
+
+use std::io::Result;
+
+pub struct Status;
+
+impl Status {
+ pub fn new() -> Self {
+ Status
+ }
+}
+
+impl super::Command for Status {
+ fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
+ vec![]
+ }
+
+ fn execute(&self, _: Option<&String>) -> Result<()> {
+ let status_providers = available_status_providers();
+ for status_provider in status_providers {
+ println!("{}", status_provider());
+ }
+ return Ok(())
+ }
+
+ fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
+ vec![]
+ }
+
+ fn command(&self) -> &'static str {
+ "status"
+ }
+
+ fn help(&self) -> &'static str {
+ "\t\t\t\tPrints the status of your blog"
+ }
+}
+
+fn available_status_providers() -> Vec<fn() -> String> {
+ vec![
+ configuration_status::status,
+ ]
+}