From f70c3cdd43fc975c2d3234c4c2449c29f8af3ba7 Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Mon, 30 Nov 2020 17:24:55 +0100 Subject: [PATCH] panic => delete all notes --- src/main.rs | 1 + src/rnote/app.rs | 1 + src/rnote/notes.rs | 2 +- src/rnote/process.rs | 6 ++++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a4e4f29..e867e24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,7 @@ fn main() -> Result<()> { ("list", Some(m)) => process::list(m)?, ("show", Some(m)) => process::show(m)?, ("search", Some(m)) => process::search(m)?, + ("panic", _) => process::panic()?, _ => app.print_long_help()?, }; diff --git a/src/rnote/app.rs b/src/rnote/app.rs index 9e1b371..4f90349 100644 --- a/src/rnote/app.rs +++ b/src/rnote/app.rs @@ -73,4 +73,5 @@ pub fn make_app() -> App<'static, 'static> { ) .arg(Arg::with_name("header").help("Name of the note.")), ) + .subcommand(SubCommand::with_name("panic").help("Delete all notes.")) } diff --git a/src/rnote/notes.rs b/src/rnote/notes.rs index 57b6ee4..693f918 100644 --- a/src/rnote/notes.rs +++ b/src/rnote/notes.rs @@ -6,7 +6,7 @@ use std::{env, fs, io::Write, os::unix::fs::PermissionsExt, process::Command}; use walkdir::WalkDir; /// Get the path to the root directory of all notes. -fn get_base_path() -> Result { +pub fn get_base_path() -> Result { let home = env::var("HOME")?; Ok(format!("{}/.rnote/", home)) } diff --git a/src/rnote/process.rs b/src/rnote/process.rs index 55be8c2..819d7dc 100644 --- a/src/rnote/process.rs +++ b/src/rnote/process.rs @@ -95,3 +95,9 @@ pub fn show(matches: &ArgMatches) -> Result<()> { } Ok(()) } + +pub fn panic() -> Result<()> { + let base = notes::get_base_path()?; + std::fs::remove_dir_all(base)?; + Ok(()) +}