jensmemesclient/cli/src/commands/search.rs

29 lines
572 B
Rust
Raw Normal View History

2020-12-05 22:20:08 +01:00
use anyhow::Result;
use reqwest::Client;
use crate::util;
pub async fn run(http: &Client, query: String) -> Result<()> {
let memes = util::memes(http).await?;
let mut matches = vec![];
for meme in memes {
if let Some(score) = fuzzy_matcher::clangd::fuzzy_match(meme.file_name()?, &query) {
matches.push((meme, score));
}
}
2020-12-05 22:31:02 +01:00
matches.sort_by(|a, b| b.1.cmp(&a.1));
2020-12-05 22:20:08 +01:00
let mut table = util::list_table();
for m in matches {
table.add_row(m.0.into());
}
println!("{}", table.render());
Ok(())
}