1 use std::fs::{create_dir_all, remove_dir_all, rename};
9 use crate::configuration::Configuration;
14 pub fn new() -> Self {
19 impl super::Command for Add {
20 fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
21 vec![Box::new(SyncDown::new())]
24 fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
25 create_dir_all(&configuration.posts_directory)?;
26 for i in (0..configuration.max_posts - 1).rev() {
27 let source = configuration.posts_directory.join(i.to_string());
28 let target = configuration.posts_directory.join((i + 1).to_string());
31 remove_dir_all(&target)?;
34 rename(&source, &target)?;
40 fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
42 Box::new(Update::new()),
43 Box::new(Generate::new()),
44 Box::new(SyncUp::new())
48 fn command(&self) -> &'static str {
52 fn help(&self) -> &'static str {
53 "<path_to_post>\t\t\tCreates new blog post"