about summary refs log tree commit diff
path: root/src/actions/create.rs
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-09-20 22:25:55 +0200
committerMel <einebeere@gmail.com>2021-09-20 22:25:55 +0200
commitc25d22681f9bc6ddba512895182af0ce0252731b (patch)
treeeadcdec7d0b4d26d59e77169bd89b8db13e22fb6 /src/actions/create.rs
parent8bcbf51cf4f7924600eae39db67ff653b48ad95d (diff)
downloadka-c25d22681f9bc6ddba512895182af0ce0252731b.tar.zst
ka-c25d22681f9bc6ddba512895182af0ce0252731b.zip
Split out common logic
Diffstat (limited to 'src/actions/create.rs')
-rw-r--r--src/actions/create.rs20
1 files changed, 20 insertions, 0 deletions
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(())
+}