Merge branch 'panic' into 'main'

panic => delete all notes

See merge request paris8-rust/rnote!6
This commit is contained in:
Volodymyr Patuta 2020-11-30 17:27:59 +01:00
commit 9e5f0a3b74
4 changed files with 9 additions and 1 deletions

View File

@ -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()?,
};

View File

@ -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."))
}

View File

@ -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<String> {
pub fn get_base_path() -> Result<String> {
let home = env::var("HOME")?;
Ok(format!("{}/.rnote/", home))
}

View File

@ -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(())
}