SimpleLogger error handling, update CI and code format

This commit is contained in:
MedzikUser 2022-01-26 19:55:08 +01:00
parent 60e7ba5bec
commit 62c0352345
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
15 changed files with 91 additions and 73 deletions

View File

@ -1,6 +1,11 @@
name: Build release binaries (and publish them if this is a tag)
on: [push, pull_request]
on:
push:
paths-ignore:
- '*.md'
pull_request:
jobs:
binaries:

View File

@ -2,7 +2,11 @@ name: Rust
on:
push:
branches: [ main ]
branches:
- main
paths-ignore:
- '*.md'
env:
CARGO_TERM_COLOR: always
@ -19,23 +23,23 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: cargo build
uses: actions-rs/cargo@v1
with:
command: build
- name: cargo build
uses: actions-rs/cargo@v1
with:
command: build
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

View File

@ -2,7 +2,11 @@ name: Rust fmt
on:
push:
branches: [ main ]
branches:
- main
paths-ignore:
- '*.md'
env:
CARGO_TERM_COLOR: always
@ -12,34 +16,34 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Setup GIT
run: |
git config --global user.name "MedzikUserBot"
git config --global user.email "rm99iv9s@duck.com"
- name: Setup GIT
run: |
git config --global user.name "MedzikUserBot"
git config --global user.email "rm99iv9s@duck.com"
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all
- name: cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all
- name: Commit changes
run: |
git add .
git diff-index --quiet HEAD || git commit -m "rustfmt"
- name: Commit changes
run: |
git add .
git diff-index --quiet HEAD || git commit -m "rustfmt"
- name: Push changes
uses: ad-m/github-push-action@b007e7b818e33b04afd056e4c4b57ba917145d7a
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: 'main'
- name: Push changes
uses: ad-m/github-push-action@b007e7b818e33b04afd056e4c4b57ba917145d7a
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: 'main'

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased]
- SimpleLogger init error handling
## [0.2.0] - 2022-01-23
### Added

View File

@ -1,6 +1,7 @@
use super::send_api_request;
use crate::api::configuration::{api_url, ImgurHandle};
use super::send_api_request;
use log::error;
use reqwest::Method;
use std::process::exit;

View File

@ -1,7 +1,8 @@
use super::send_api_request;
use crate::api::configuration::{api_url, ImgurHandle};
use crate::api::ImageInfo;
use super::send_api_request;
use log::error;
use reqwest::Method;
use std::process::exit;

View File

@ -1,6 +1,7 @@
use super::send_api_request;
use crate::api::configuration::{api_url, ImgurHandle};
use super::send_api_request;
use log::error;
use reqwest::Method;
use serde_derive::{Deserialize, Serialize};

View File

@ -1,6 +1,6 @@
use reqwest::Method;
use super::ImgurHandle;
use reqwest::Method;
use std::collections::HashMap;
pub async fn send_api_request(

View File

@ -1,9 +1,10 @@
use super::send_api_request;
use crate::api::{
configuration::{api_url, ImgurHandle},
ImageInfo,
};
use super::send_api_request;
use log::error;
use reqwest::Method;
use std::{collections::HashMap, process::exit};

View File

@ -1,8 +1,7 @@
use imgurs::api::{rate_limit::rate_limit, ImgurHandle};
use log::{error, info};
use chrono::{prelude::DateTime, Utc};
use log::{error, info};
use std::{
process::exit,
time::{Duration, UNIX_EPOCH},

View File

@ -4,19 +4,17 @@ pub mod info_image;
pub mod parse;
pub mod upload_image;
use crate::config::toml::parse;
use imgurs::api::ImageInfo;
use chrono::{prelude::DateTime, Utc};
use log::{error, info};
use notify_rust::Notification;
use std::{
process::exit,
time::{Duration, UNIX_EPOCH},
};
use imgurs::api::ImageInfo;
use notify_rust::Notification;
use crate::config::toml::parse;
pub fn print_image_info(i: ImageInfo, notify: bool) {
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
let datetime = DateTime::<Utc>::from(d);

View File

@ -1,11 +1,10 @@
use imgurs::api::configuration::ImgurHandle;
use clap::{App, AppSettings, IntoApp, Parser, Subcommand};
use clap_complete::{generate, Generator, Shell};
use log::error;
use std::io::stdout;
use imgurs::api::configuration::ImgurHandle;
use crate::cli::{credits::*, delete_image::*, info_image::*, upload_image::*};
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");

View File

@ -1,6 +1,7 @@
use super::print_image_info;
use imgurs::api::{configuration::ImgurHandle, upload_image::upload_image as upload_img};
use super::print_image_info;
use base64::encode as base64_encode;
use log::error;
use std::{fs::read as fs_read, path::Path, process::exit};

View File

@ -1,15 +1,14 @@
use dirs::config_dir;
use toml::from_str;
use super::Config;
use log::{error, warn};
use dirs::config_dir;
use log::{error, warn};
use std::{
fs::{create_dir_all, read_to_string, File},
io::Write as _,
path::Path,
process::exit,
};
use toml::from_str;
pub fn parse() -> Config {
toml().unwrap_or_else(|e| {

View File

@ -2,18 +2,22 @@ mod cli;
mod config;
use cli::parse::parse;
use simple_logger::SimpleLogger;
use imgurs::api::ImgurHandle;
use log::error;
use simple_logger::SimpleLogger;
use std::process::exit;
#[tokio::main]
async fn main() {
SimpleLogger::new().init().unwrap();
SimpleLogger::new().init().unwrap_or_else(|e| {
error!("init simple logger: {e}");
exit(2)
});
let config = config::toml::parse();
let client = ImgurHandle::new((&config.imgur.id).to_string());
parse(client).await;
parse(client).await
}