fix clippy

This commit is contained in:
MedzikUser 2022-04-03 21:11:11 +02:00
parent b1bfe52a4c
commit 08c25212ae
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
9 changed files with 25 additions and 22 deletions

View File

@ -43,7 +43,7 @@ impl ImgurClient {
format!("{path} is not url or file path"), format!("{path} is not url or file path"),
); );
Err(anyhow::Error::from(err))? return Err(err.into());
} }
upload_image(self, image).await upload_image(self, image).await

View File

@ -28,7 +28,7 @@ pub async fn delete_image(client: &ImgurClient, delete_hash: String) -> Result<(
format!("server returned non-successful status code = {status}, body = {body}"), format!("server returned non-successful status code = {status}, body = {body}"),
); );
Err(err)? return Err(err.into());
} }
Ok(()) Ok(())

View File

@ -22,7 +22,7 @@ pub async fn get_image(client: &ImgurClient, image: String) -> Result<ImageInfo,
format!("server returned non-successful status code = {status}"), format!("server returned non-successful status code = {status}"),
); );
Err(err)? Err(err.into())
} else { } else {
let content: ImageInfo = res.json().await?; let content: ImageInfo = res.json().await?;
Ok(content) Ok(content)

View File

@ -15,8 +15,8 @@ pub use upload_image::*;
use std::collections::HashMap; use std::collections::HashMap;
use reqwest::{Response, Method};
use anyhow::Error; use anyhow::Error;
use reqwest::{Method, Response};
// send request to imgur api // send request to imgur api
pub async fn send_api_request( pub async fn send_api_request(
@ -38,10 +38,7 @@ pub async fn send_api_request(
// add `Authorization` and `User-Agent` to request // add `Authorization` and `User-Agent` to request
req = req req = req
.header("Authorization", format!("Client-ID {}", config.client_id)) .header("Authorization", format!("Client-ID {}", config.client_id))
.header( .header("User-Agent", format!("Imgur/{:?}", version));
"User-Agent",
format!("Imgur/{:?}", version),
);
// if exists add hashmap to request // if exists add hashmap to request
if form != None { if form != None {

View File

@ -46,7 +46,7 @@ pub async fn rate_limit(client: &ImgurClient) -> Result<RateLimitInfo, Error> {
format!("server returned non-successful status code = {status}, body = {body}"), format!("server returned non-successful status code = {status}, body = {body}"),
); );
Err(err)? Err(err.into())
} else { } else {
let content = res.json::<RateLimitInfo>().await?; let content = res.json::<RateLimitInfo>().await?;
Ok(content) Ok(content)

View File

@ -5,7 +5,7 @@ use reqwest::Method;
use super::{client::api_url, send_api_request, ImageInfo, ImgurClient}; use super::{client::api_url, send_api_request, ImageInfo, ImgurClient};
pub async fn upload_image(c: &ImgurClient, image: String) -> Result<ImageInfo, Error> { pub async fn upload_image(client: &ImgurClient, image: String) -> Result<ImageInfo, Error> {
// create http form (hashmap) // create http form (hashmap)
let mut form = HashMap::new(); let mut form = HashMap::new();
// insert image to form // insert image to form
@ -15,7 +15,7 @@ pub async fn upload_image(c: &ImgurClient, image: String) -> Result<ImageInfo, E
let uri = api_url!("image"); let uri = api_url!("image");
// send request to imgur api // send request to imgur api
let res = send_api_request(&c, Method::POST, uri, Some(form)).await?; let res = send_api_request(client, Method::POST, uri, Some(form)).await?;
// get response http code // get response http code
let status = res.status(); let status = res.status();
@ -33,7 +33,7 @@ pub async fn upload_image(c: &ImgurClient, image: String) -> Result<ImageInfo, E
format!("server returned non-successful status code = {status}, body = {body}"), format!("server returned non-successful status code = {status}, body = {body}"),
); );
Err(err)? Err(err.into())
} else { } else {
let content: ImageInfo = res.json().await?; let content: ImageInfo = res.json().await?;
Ok(content) Ok(content)

View File

@ -59,7 +59,7 @@ pub fn set_clipboard(content: String) {
"command for clipboard not found".magenta() "command for clipboard not found".magenta()
); );
return return;
} }
// copy the content (send it to stdin command) // copy the content (send it to stdin command)
@ -81,5 +81,7 @@ pub fn set_clipboard(content: String) {
)))] )))]
pub fn set_clipboard(content: String) { pub fn set_clipboard(content: String) {
let mut clipboard = arboard::Clipboard::new().unwrap(); let mut clipboard = arboard::Clipboard::new().unwrap();
clipboard.set_text(content).execute(format!("set clipboard to '{content}'")); clipboard
.set_text(content)
.execute(format!("set clipboard to '{content}'"));
} }

View File

@ -1,11 +1,14 @@
mod parse;
pub mod clipboard; pub mod clipboard;
pub mod credits; pub mod credits;
pub mod delete_image; pub mod delete_image;
pub mod info_image; pub mod info_image;
pub mod parse;
pub mod upload_image; pub mod upload_image;
pub mod webhook; pub mod webhook;
pub use parse::*;
use chrono::{prelude::DateTime, Utc}; use chrono::{prelude::DateTime, Utc};
use colored::Colorize; use colored::Colorize;
use imgurs::ImageInfo; use imgurs::ImageInfo;

View File

@ -1,18 +1,19 @@
use imgurs::ImgurClient;
use simple_logger::SimpleLogger;
mod cli; mod cli;
mod config; mod config;
use cli::parse::parse;
use imgurs::ImgurClient;
use simple_logger::SimpleLogger;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
SimpleLogger::new().init().expect("init SimpleLogger"); SimpleLogger::new().init().expect("init SimpleLogger");
better_panic::install(); better_panic::install();
// parse config file
let config = config::toml::parse(); let config = config::toml::parse();
let client = ImgurClient::new((&config.imgur.id).to_string());
parse(client).await // create imgur client
let client = ImgurClient::new(config.imgur.id);
cli::parse(client).await
} }