diff --git a/src/rnote/app.rs b/src/rnote/app.rs index ffa3b41..e267de4 100644 --- a/src/rnote/app.rs +++ b/src/rnote/app.rs @@ -66,6 +66,14 @@ pub fn make_app() -> App<'static, 'static> { .short("a") .long("all"), ) + .arg( + Arg::with_name("category") + .help("Show all notes from a category/date") + .short("c") + .short("d") + .long("category") + .long("date"), + ) .arg(Arg::with_name("header").help("Name of the note.")), ) } diff --git a/src/rnote/notes.rs b/src/rnote/notes.rs index 3df9b63..4d25fc4 100644 --- a/src/rnote/notes.rs +++ b/src/rnote/notes.rs @@ -190,3 +190,37 @@ pub fn show_all() -> Result<()> { show::run_app(skin, md)?; Ok(()) } + +pub fn show(header: &str) -> Result<()> { + let path = find_path(header)?; + match path { + Some(s) => { + let skin = show::make_skin(); + let content = fs::read_to_string(s)?; + show::run_app(skin, &content)?; + Ok(()) + } + None => Err(anyhow!("Abort.")), + } +} + +pub fn show_category(category: &str) -> Result<()> { + let base = get_base_path()?; + let path = format!("{}{}", base, category); + let mut files: Vec = Vec::new(); + if std::path::Path::new(&path).exists() { + for (_, file) in WalkDir::new(path) + .into_iter() + .filter_map(|file| file.ok()) + .enumerate() + { + if file.metadata()?.is_file() { + files.push(fs::read_to_string(file.path())?); + } + } + let skin = show::make_skin(); + let md = &files.join("---\n"); + show::run_app(skin, md)?; + } + Ok(()) +} diff --git a/src/rnote/process.rs b/src/rnote/process.rs index cb4b730..6a64fff 100644 --- a/src/rnote/process.rs +++ b/src/rnote/process.rs @@ -70,10 +70,18 @@ pub fn search(matches: &ArgMatches) -> Result<()> { pub fn show(matches: &ArgMatches) -> Result<()> { match matches.value_of("header") { - Some(s) => unimplemented!("{}", s), + Some(s) => notes::show(s)?, None => match matches.is_present("all") { true => notes::show_all()?, - false => return Err(anyhow!("No option is given. Abort.")), + false => match matches.is_present("category") { + true => { + let category: String = Input::with_theme(&ColorfulTheme::default()) + .with_prompt("Name of category:") + .interact_text()?; + notes::show_category(&category)?; + } + false => return Err(anyhow!("No option is given. Abort.")), + }, }, } Ok(())