diff --git a/src/rnote/app.rs b/src/rnote/app.rs index b98ad42..4bef840 100644 --- a/src/rnote/app.rs +++ b/src/rnote/app.rs @@ -12,7 +12,7 @@ pub fn make_app() -> App<'static, 'static> { .alias("n") .about("Create new note") .arg( - Arg::with_name("header") + Arg::with_name("name") .index(1) .help("Give name to the note."), ) @@ -27,12 +27,12 @@ pub fn make_app() -> App<'static, 'static> { .alias("r") .alias("rm") .about("Remove a note.") - .arg(Arg::with_name("header").help("Name of the note.")) + .arg(Arg::with_name("name").help("Name of the note.")) .arg( Arg::with_name("date") .help("Delete all notes created at given date.") .short("d") - .conflicts_with("header") + .conflicts_with("name") .long("date"), ), ) @@ -40,7 +40,7 @@ pub fn make_app() -> App<'static, 'static> { SubCommand::with_name("edit") .alias("e") .about("Edit a note.") - .arg(Arg::with_name("header").help("Name of the note.")), + .arg(Arg::with_name("name").help("Name of the note.")), ) .subcommand( SubCommand::with_name("list") @@ -62,10 +62,10 @@ pub fn make_app() -> App<'static, 'static> { Arg::with_name("word") .help("Search by word.") .short("w") - .conflicts_with("header") + .conflicts_with("name") .long("word"), ) - .arg(Arg::with_name("header").help("Name of the note.")), + .arg(Arg::with_name("name").help("Name of the note.")), ) .subcommand( SubCommand::with_name("show") @@ -74,7 +74,7 @@ pub fn make_app() -> App<'static, 'static> { Arg::with_name("all") .help("Show all notes.") .short("a") - .conflicts_with("header") + .conflicts_with("name") .long("all"), ) .arg( @@ -82,9 +82,9 @@ pub fn make_app() -> App<'static, 'static> { .help("Show all notes from a category/date.") .short("c") .long("category") - .conflicts_with("header"), + .conflicts_with("name"), ) - .arg(Arg::with_name("header").help("Name of the note.")), + .arg(Arg::with_name("name").help("Name of the note.")), ) .subcommand(SubCommand::with_name("panic").about("Delete all notes.")) } diff --git a/src/rnote/notes.rs b/src/rnote/notes.rs index adbaee2..ce8e015 100644 --- a/src/rnote/notes.rs +++ b/src/rnote/notes.rs @@ -97,21 +97,21 @@ pub fn create_dir(category: &str) -> Result<()> { } /// Find a path to desired note. -pub fn get_note_path(header: &str) -> Result> { +pub fn get_note_path(name: &str) -> Result> { let mut paths: Vec = Vec::new(); let base = get_base_path()?; - let header = format!("{}.md", header); + let name = format!("{}.md", name); for entry in WalkDir::new(base) { let entry = entry?; let p: String = match entry.path().to_str() { Some(s) => s.to_owned(), None => "".to_owned(), }; - let name: &str = match entry.file_name().to_str() { + let file_name: &str = match entry.file_name().to_str() { Some(s) => s, None => "", }; - if name == header { + if file_name == name { paths.push(p); } } @@ -149,31 +149,31 @@ pub fn get_files_by_word(word: &str) -> Result> { } /// Create a new note. -pub fn create(header: &str, category: &str) -> Result<()> { +pub fn create(name: &str, category: &str) -> Result<()> { let editor = env::var("EDITOR")?; - let file = format!("{}{}.md", get_category_path(category)?, header); + let file = format!("{}{}.md", get_category_path(category)?, name); create_dir(category)?; - is_duplicate(header, category)?; + is_duplicate(name, category)?; let mut f = fs::File::create(&file)?; let username = env::var("USER").unwrap_or("".to_owned()); let date = Utc::now().format("%d-%m-%Y"); - let note_header = format!( + let note_name = format!( r#"--- title: {} author: {} date: {} ---"#, - header, username, date + name, username, date ); f.set_permissions(fs::Permissions::from_mode(0o600))?; - f.write(format!("{}\n", note_header).as_bytes())?; + f.write(format!("{}\n", note_name).as_bytes())?; Command::new(editor).arg(&file).status()?; Ok(()) } /// Check if potentially new note name already exists. -fn is_duplicate(header: &str, category: &str) -> Result<()> { - let file = format!("{}{}.md", get_category_path(category)?, header); +fn is_duplicate(name: &str, category: &str) -> Result<()> { + let file = format!("{}{}.md", get_category_path(category)?, name); let path = format!("{}", get_category_path(category)?); for entry in WalkDir::new(path) { let entry = entry?; @@ -191,8 +191,8 @@ fn is_duplicate(header: &str, category: &str) -> Result<()> { } /// Find a path to desired note and prompt to choose one to open. -pub fn get_note_path_interractive(header: &str) -> Result> { - let mut paths: Vec = get_note_path(header)?; +pub fn get_note_path_interractive(name: &str) -> Result> { + let mut paths: Vec = get_note_path(name)?; let mut p: Vec = paths.clone(); let r = p[0].find("rnote").unwrap_or(0); p = p.into_iter().map(|mut s| s.drain(r..).collect()).collect(); @@ -221,13 +221,13 @@ pub fn remove_note(path: &str) -> Result<()> { } /// Prompt user to delete a note. -pub fn remove_interractive(header: &str) -> Result<()> { - let path = get_note_path_interractive(header)?; +pub fn remove_interractive(name: &str) -> Result<()> { + let path = get_note_path_interractive(name)?; if path.is_none() { return Err(anyhow!("Abort.")); } if Confirm::with_theme(&ColorfulTheme::default()) - .with_prompt(format!("Do you want to delete {}?", header)) + .with_prompt(format!("Do you want to delete {}?", name)) .interact()? { remove_note(&path.unwrap())?; @@ -238,9 +238,9 @@ pub fn remove_interractive(header: &str) -> Result<()> { } /// Modify a note. -pub fn modify(header: &str) -> Result<()> { +pub fn modify(name: &str) -> Result<()> { let editor = env::var("EDITOR")?; - let file = get_note_path_interractive(header)?; + let file = get_note_path_interractive(name)?; match file { Some(f) => { Command::new(editor).arg(f).status()?; @@ -298,8 +298,8 @@ pub fn show_all() -> Result<()> { } /// Show one note. -pub fn show(header: &str) -> Result<()> { - let path = get_note_path_interractive(header)?; +pub fn show(name: &str) -> Result<()> { + let path = get_note_path_interractive(name)?; match path { Some(s) => { let skin = show::make_skin(); diff --git a/src/rnote/process.rs b/src/rnote/process.rs index d14642e..1a9d167 100644 --- a/src/rnote/process.rs +++ b/src/rnote/process.rs @@ -5,7 +5,7 @@ use dialoguer::{theme::ColorfulTheme, Input}; /// Process argument `new`. pub fn new(matches: &ArgMatches) -> Result<()> { - let header = match matches.value_of("header") { + let name = match matches.value_of("name") { Some(s) => s.to_owned(), None => Input::with_theme(&ColorfulTheme::default()) .with_prompt("Name of your note") @@ -19,13 +19,13 @@ pub fn new(matches: &ArgMatches) -> Result<()> { .interact_text()?, }; - notes::create(&header, &category)?; + notes::create(&name, &category)?; Ok(()) } /// Process argument `remove`. pub fn remove(matches: &ArgMatches) -> Result<()> { - match matches.value_of("header") { + match matches.value_of("name") { Some(s) => notes::remove_interractive(s)?, None => match matches.is_present("date") { true => { @@ -36,10 +36,10 @@ pub fn remove(matches: &ArgMatches) -> Result<()> { return Ok(()); } false => { - let header: String = Input::with_theme(&ColorfulTheme::default()) + let name: String = Input::with_theme(&ColorfulTheme::default()) .with_prompt("Name of your note") .interact_text()?; - notes::remove_interractive(&header)?; + notes::remove_interractive(&name)?; } }, } @@ -48,14 +48,14 @@ pub fn remove(matches: &ArgMatches) -> Result<()> { /// Process argument `remove`. pub fn edit(matches: &ArgMatches) -> Result<()> { - let header = match matches.value_of("header") { + let name = match matches.value_of("name") { Some(s) => s.to_owned(), None => Input::with_theme(&ColorfulTheme::default()) .with_prompt("Name of your note") .interact_text()?, }; - notes::modify(&header)?; + notes::modify(&name)?; Ok(()) } @@ -75,7 +75,7 @@ pub fn list(matches: &ArgMatches) -> Result<()> { /// Process argument `search`. pub fn search(matches: &ArgMatches) -> Result<()> { - match matches.value_of("header") { + match matches.value_of("name") { Some(s) => { let p = notes::get_note_path_interractive(s)?; match p { @@ -101,7 +101,7 @@ pub fn search(matches: &ArgMatches) -> Result<()> { /// Process argument `show`. pub fn show(matches: &ArgMatches) -> Result<()> { - match matches.value_of("header") { + match matches.value_of("name") { Some(s) => notes::show(s)?, None => match matches.is_present("all") { true => notes::show_all()?,