-use std::fs::{create_dir_all, rename};
+use std::fs::{create_dir_all, remove_dir_all, rename};
use std::io::Result;
use super::{
generate::Generate,
fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
create_dir_all(&configuration.posts_directory)?;
- for i in (0..configuration.max_posts).rev() {
+ for i in (0..configuration.max_posts - 1).rev() {
let source = configuration.posts_directory.join(i.to_string());
let target = configuration.posts_directory.join((i + 1).to_string());
+ if target.exists() {
+ remove_dir_all(&target)?;
+ }
if source.exists() {
rename(&source, &target)?;
}
--- /dev/null
+use std::fs::read_dir;
+use std::path::PathBuf;
+use crate::configuration::Configuration;
+
+pub fn status(configuration: &Configuration) -> String {
+ let mut status_message = String::new();
+
+ status_message.push_str("# Blog\n");
+
+ // Main Configuration Locations
+ let blog_count = count_entries(&configuration.posts_directory);
+ status_message.push_str(&format!("Number of posts in blog: {}\n", blog_count));
+
+ let archive_count = count_entries(&configuration.archive_directory);
+ status_message.push_str(&format!("Number of posts in archive: {}\n", archive_count));
+ status_message
+}
+
+fn count_entries(path: &PathBuf) -> String {
+ match read_dir(path) {
+ Ok(entries) => entries.filter_map(Result::ok).count().to_string(),
+ Err(_) => "0".to_string()
+ }
+}
mod configuration_status;
+mod blog_status;
use std::io::Result;
use crate::configuration::Configuration;
fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
let status_providers = available_status_providers();
for status_provider in status_providers {
- println!("{}", status_provider(configuration));
+ println!("{}\n----\n", status_provider(configuration));
}
return Ok(())
}
fn available_status_providers() -> Vec<fn(&Configuration) -> String> {
vec![
configuration_status::status,
+ blog_status::status,
]
}