Merge branch 'test' into 'main'
search See merge request paris8-rust/rnote!2
This commit is contained in:
commit
5260fc12b6
@ -13,3 +13,4 @@ walkdir = "2.3.1"
|
||||
text_io = "0.1.8"
|
||||
clap = "2.33.3"
|
||||
dialoguer = "0.7.1"
|
||||
fstream = "0.1.2"
|
||||
|
@ -51,12 +51,12 @@ pub fn make_app() -> App<'static, 'static> {
|
||||
SubCommand::with_name("search")
|
||||
.alias("s")
|
||||
.about("Search a note.")
|
||||
.arg(Arg::with_name("header").help("Name of the note."))
|
||||
.arg(
|
||||
Arg::with_name("word")
|
||||
.help("Search by word.")
|
||||
.short("w")
|
||||
.long("word"),
|
||||
),
|
||||
)
|
||||
.arg(Arg::with_name("header").help("Name of the note.")),
|
||||
)
|
||||
}
|
||||
|
@ -120,3 +120,29 @@ pub fn modify(header: &str) -> Result<()> {
|
||||
println!("Edited successfully!");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn search_by_word(word: &str) -> Result<()> {
|
||||
extern crate fstream;
|
||||
let path = get_base_path()?;
|
||||
for (_, file) in WalkDir::new(path)
|
||||
.into_iter()
|
||||
.filter_map(|file| file.ok())
|
||||
.enumerate()
|
||||
{
|
||||
if file.metadata()?.is_file() {
|
||||
match fstream::contains(file.path(), word) {
|
||||
Some(b) => {
|
||||
if b {
|
||||
let path = file.path().to_str().unwrap_or("");
|
||||
if !path.is_empty() {
|
||||
println!("{}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::rnote::notes;
|
||||
use anyhow::Result;
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::ArgMatches;
|
||||
use dialoguer::{theme::ColorfulTheme, Input};
|
||||
use text_io::read;
|
||||
@ -42,5 +42,17 @@ pub fn list(matches: &ArgMatches) -> Result<()> {
|
||||
unimplemented!("list all notes, one note or category {:?}", matches);
|
||||
}
|
||||
pub fn search(matches: &ArgMatches) -> Result<()> {
|
||||
unimplemented!("Search a note by header or by word. {:?}", matches);
|
||||
match matches.value_of("header") {
|
||||
Some(s) => unimplemented!("{}", s),
|
||||
None => match matches.is_present("word") {
|
||||
true => {
|
||||
let s: String = Input::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("String to search")
|
||||
.interact_text()?;
|
||||
notes::search_by_word(&s)?;
|
||||
}
|
||||
false => return Err(anyhow!("Nothing entered for search.")),
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user