added rand command and aliases

This commit is contained in:
LordMZTE 2021-12-26 14:37:50 +01:00
parent e2ce737497
commit 9a4a5c5578
6 changed files with 33 additions and 37 deletions

View file

@ -1,6 +1,5 @@
# v1.1.0
# v1.1.1
## cli
- removed fzf integration
- improved tables
- works with new API!
- added some command aliases
- added rand command

View file

@ -24,7 +24,7 @@ comfy-table = "5.0.0"
env_logger = "0.9.0"
fuzzy-matcher = "0.3.7"
indicatif = "0.16.2"
libjens = { git = "https://tilera.xyz/git/LordMZTE/libjens.git", rev = "1.0.1" }
libjens = { git = "https://tilera.xyz/git/LordMZTE/libjens.git", rev = "1.1.0" }
log = "0.4.14"
opener = "0.5.0"
reqwest = { version = "0.11.8", features = ["stream", "multipart"] }

View file

@ -1,5 +1,6 @@
pub mod cats;
pub mod list;
pub mod rand;
pub mod search;
pub mod up;
pub mod users;

21
cli/src/commands/rand.rs Normal file
View file

@ -0,0 +1,21 @@
use anyhow::Result;
use chrono::{Local, TimeZone};
use libjens::JMClient;
pub async fn run(client: &JMClient) -> Result<()> {
let meme = client.get_random().await?;
println!(
"\
Link: {}
Category: {}
User: {}
Timestamp: {}",
meme.link,
meme.category,
meme.user,
Local.timestamp(meme.timestamp, 0).format("%F %R")
);
Ok(())
}

View file

@ -39,10 +39,10 @@ enum Cmd {
open: bool,
},
#[structopt(about = "lists the available categories")]
#[structopt(about = "lists the available categories", alias = "c")]
Cats,
#[structopt(about = "searches for a meme")]
#[structopt(about = "searches for a meme", alias = "s")]
Search {
query: String,
@ -79,8 +79,11 @@ enum Cmd {
sort: Option<MemeSorting>,
},
#[structopt(about = "Lists all users")]
#[structopt(about = "Lists all users", alias = "u")]
Users,
#[structopt(about = "Gets a random meme", alias = "r")]
Rand,
}
#[tokio::main]
@ -115,6 +118,7 @@ async fn main() -> Result<()> {
sort,
} => commands::list::run(&client, category, user, sort).await?,
Cmd::Users => commands::users::run(&client).await?,
Cmd::Rand => commands::rand::run(&client).await?,
}
Ok(())

View file

@ -2,35 +2,6 @@ use chrono::{Local, TimeZone};
use comfy_table::{presets::UTF8_NO_BORDERS, ContentArrangement, Row, Table};
use libjens::api::{Category, Meme, User};
// pub trait AsTableRow {
// fn as_table_row(&self) -> term_table::row::Row;
//}
// impl AsTableRow for Category {
// fn as_table_row(&self) -> Row<'_> {
// Row::new(vec![TableCell::new(&self.id), TableCell::new(&self.name)])
// }
//}
// impl AsTableRow for Meme {
// fn as_table_row(&self) -> Row<'_> {
// Row::new(vec![
// TableCell::new(&self.link),
// TableCell::new(&self.category),
// TableCell::new(&self.user),
// TableCell::new(Local.timestamp(self.timestamp, 0).format("%F
// %R")), TableCell::new(&self.id),
// ])
// }
//}
// impl AsTableRow for User {
// fn as_table_row(&self) -> Row<'_> {
// Row::new(vec![
// TableCell::new(&self.name),
// TableCell::new(&self.get_id().map(String::as_ref).unwrap_or("[No
// ID]")), TableCell::new(&self.dayuploads),
// ])
// }
//}
pub fn list_table() -> Table {
let mut table = Table::new();