1 use super::{generate::Generate, sync_down::SyncDown, sync_up::SyncUp, update::Update};
2 use crate::configuration::Configuration;
3 use std::fs::{create_dir_all, remove_dir_all, rename};
14 impl super::Command for Add {
15 fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
16 vec![Box::new(SyncDown::new())]
19 fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &str) -> Result<()> {
20 create_dir_all(&configuration.posts_directory)?;
21 for i in (0..configuration.max_posts - 1).rev() {
22 let source = configuration.posts_directory.join(i.to_string());
23 let target = configuration.posts_directory.join((i + 1).to_string());
26 remove_dir_all(&target)?;
29 rename(&source, &target)?;
35 fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
37 Box::new(Update::new()),
38 Box::new(Generate::new()),
39 Box::new(SyncUp::new()),
43 fn command(&self) -> &'static str {
47 fn help(&self) -> &'static str {
48 "<path_to_post>\t\t\tCreates new blog post"