From c25d22681f9bc6ddba512895182af0ce0252731b Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 20 Sep 2021 22:25:55 +0200 Subject: Split out common logic --- src/actions/create.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/actions/create.rs (limited to 'src/actions/create.rs') diff --git a/src/actions/create.rs b/src/actions/create.rs new file mode 100644 index 0000000..26d20c8 --- /dev/null +++ b/src/actions/create.rs @@ -0,0 +1,20 @@ +use std::{fs, io}; + +use crate::{actions::update, files::Locations}; + +use super::ActionOptions; + +pub fn create(command_options: ActionOptions) -> io::Result<()> { + let locations = Locations::from(&command_options); + + if locations.ka_path.exists() { + fs::remove_dir_all(locations.ka_path.as_path())?; + } + + fs::create_dir(locations.ka_path)?; + fs::create_dir(locations.ka_files_path)?; + + update(command_options)?; + + Ok(()) +} -- cgit 1.4.1