search by word with word as an argument
And error if no files with a given word found.
This commit is contained in:
parent
beaa8a8119
commit
536624480a
@ -70,7 +70,6 @@ pub fn make_app() -> App<'static, 'static> {
|
|||||||
Arg::with_name("word")
|
Arg::with_name("word")
|
||||||
.help("Search by word.")
|
.help("Search by word.")
|
||||||
.short("w")
|
.short("w")
|
||||||
.conflicts_with("name")
|
|
||||||
.long("word"),
|
.long("word"),
|
||||||
)
|
)
|
||||||
.arg(Arg::with_name("name").help("Name of the note.")),
|
.arg(Arg::with_name("name").help("Name of the note.")),
|
||||||
|
@ -145,7 +145,11 @@ pub fn get_files_by_word(word: &str) -> Result<Vec<String>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if paths.len() > 0 {
|
||||||
Ok(paths)
|
Ok(paths)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("No files found with word \"{}\"", word))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new note.
|
/// Create a new note.
|
||||||
|
@ -84,6 +84,16 @@ pub fn list(matches: &ArgMatches) -> Result<()> {
|
|||||||
|
|
||||||
/// Process argument `search`.
|
/// Process argument `search`.
|
||||||
pub fn search(matches: &ArgMatches) -> Result<()> {
|
pub fn search(matches: &ArgMatches) -> Result<()> {
|
||||||
|
if matches.is_present("word") {
|
||||||
|
let word: String = match matches.value_of("name") {
|
||||||
|
Some(s) => s.to_string(),
|
||||||
|
None => Input::with_theme(&ColorfulTheme::default())
|
||||||
|
.with_prompt("String to search")
|
||||||
|
.interact_text()?,
|
||||||
|
};
|
||||||
|
return notes::search_by_word(&word);
|
||||||
|
}
|
||||||
|
|
||||||
match matches.value_of("name") {
|
match matches.value_of("name") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
let p = notes::get_note_path_interractive(s)?;
|
let p = notes::get_note_path_interractive(s)?;
|
||||||
@ -92,18 +102,10 @@ pub fn search(matches: &ArgMatches) -> Result<()> {
|
|||||||
let editor = std::env::var("EDITOR")?;
|
let editor = std::env::var("EDITOR")?;
|
||||||
std::process::Command::new(editor).arg(s).status()?;
|
std::process::Command::new(editor).arg(s).status()?;
|
||||||
}
|
}
|
||||||
None => (),
|
None => return Err(anyhow!("Nothing found.")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => match matches.is_present("word") {
|
None => return Err(anyhow!("Nothing entered for search.")),
|
||||||
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user