mirror of https://github.com/MedzikUser/imgurs
SimpleLogger error handling, update CI and code format
This commit is contained in:
parent
60e7ba5bec
commit
62c0352345
|
@ -1,6 +1,11 @@
|
||||||
name: Build release binaries (and publish them if this is a tag)
|
name: Build release binaries (and publish them if this is a tag)
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
paths-ignore:
|
||||||
|
- '*.md'
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
binaries:
|
binaries:
|
||||||
|
|
|
@ -2,7 +2,11 @@ name: Rust
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
paths-ignore:
|
||||||
|
- '*.md'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
@ -19,23 +23,23 @@ jobs:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Rust toolchain
|
- name: Setup Rust toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
- name: cargo build
|
- name: cargo build
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
|
|
||||||
- name: cargo clippy
|
- name: cargo clippy
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: clippy
|
command: clippy
|
||||||
args: -- -D warnings
|
args: -- -D warnings
|
||||||
|
|
|
@ -2,7 +2,11 @@ name: Rust fmt
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
paths-ignore:
|
||||||
|
- '*.md'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
@ -12,34 +16,34 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup GIT
|
- name: Setup GIT
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name "MedzikUserBot"
|
git config --global user.name "MedzikUserBot"
|
||||||
git config --global user.email "rm99iv9s@duck.com"
|
git config --global user.email "rm99iv9s@duck.com"
|
||||||
|
|
||||||
- name: Setup Rust toolchain
|
- name: Setup Rust toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
- name: cargo fmt
|
- name: cargo fmt
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: fmt
|
command: fmt
|
||||||
args: --all
|
args: --all
|
||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
run: |
|
run: |
|
||||||
git add .
|
git add .
|
||||||
git diff-index --quiet HEAD || git commit -m "rustfmt"
|
git diff-index --quiet HEAD || git commit -m "rustfmt"
|
||||||
|
|
||||||
- name: Push changes
|
- name: Push changes
|
||||||
uses: ad-m/github-push-action@b007e7b818e33b04afd056e4c4b57ba917145d7a
|
uses: ad-m/github-push-action@b007e7b818e33b04afd056e4c4b57ba917145d7a
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
branch: 'main'
|
branch: 'main'
|
||||||
|
|
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
<!-- next-header -->
|
<!-- next-header -->
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
- SimpleLogger init error handling
|
||||||
|
|
||||||
## [0.2.0] - 2022-01-23
|
## [0.2.0] - 2022-01-23
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::send_api_request;
|
|
||||||
use crate::api::configuration::{api_url, ImgurHandle};
|
use crate::api::configuration::{api_url, ImgurHandle};
|
||||||
|
|
||||||
|
use super::send_api_request;
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use super::send_api_request;
|
|
||||||
use crate::api::configuration::{api_url, ImgurHandle};
|
use crate::api::configuration::{api_url, ImgurHandle};
|
||||||
use crate::api::ImageInfo;
|
use crate::api::ImageInfo;
|
||||||
|
|
||||||
|
use super::send_api_request;
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::send_api_request;
|
|
||||||
use crate::api::configuration::{api_url, ImgurHandle};
|
use crate::api::configuration::{api_url, ImgurHandle};
|
||||||
|
|
||||||
|
use super::send_api_request;
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use reqwest::Method;
|
|
||||||
|
|
||||||
use super::ImgurHandle;
|
use super::ImgurHandle;
|
||||||
|
|
||||||
|
use reqwest::Method;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub async fn send_api_request(
|
pub async fn send_api_request(
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use super::send_api_request;
|
|
||||||
use crate::api::{
|
use crate::api::{
|
||||||
configuration::{api_url, ImgurHandle},
|
configuration::{api_url, ImgurHandle},
|
||||||
ImageInfo,
|
ImageInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::send_api_request;
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use std::{collections::HashMap, process::exit};
|
use std::{collections::HashMap, process::exit};
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use imgurs::api::{rate_limit::rate_limit, ImgurHandle};
|
use imgurs::api::{rate_limit::rate_limit, ImgurHandle};
|
||||||
|
|
||||||
use log::{error, info};
|
|
||||||
|
|
||||||
use chrono::{prelude::DateTime, Utc};
|
use chrono::{prelude::DateTime, Utc};
|
||||||
|
use log::{error, info};
|
||||||
use std::{
|
use std::{
|
||||||
process::exit,
|
process::exit,
|
||||||
time::{Duration, UNIX_EPOCH},
|
time::{Duration, UNIX_EPOCH},
|
||||||
|
|
|
@ -4,19 +4,17 @@ pub mod info_image;
|
||||||
pub mod parse;
|
pub mod parse;
|
||||||
pub mod upload_image;
|
pub mod upload_image;
|
||||||
|
|
||||||
|
use crate::config::toml::parse;
|
||||||
|
use imgurs::api::ImageInfo;
|
||||||
|
|
||||||
use chrono::{prelude::DateTime, Utc};
|
use chrono::{prelude::DateTime, Utc};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
use notify_rust::Notification;
|
||||||
use std::{
|
use std::{
|
||||||
process::exit,
|
process::exit,
|
||||||
time::{Duration, UNIX_EPOCH},
|
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) {
|
pub fn print_image_info(i: ImageInfo, notify: bool) {
|
||||||
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
|
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
|
||||||
let datetime = DateTime::<Utc>::from(d);
|
let datetime = DateTime::<Utc>::from(d);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
|
use imgurs::api::configuration::ImgurHandle;
|
||||||
|
|
||||||
use clap::{App, AppSettings, IntoApp, Parser, Subcommand};
|
use clap::{App, AppSettings, IntoApp, Parser, Subcommand};
|
||||||
use clap_complete::{generate, Generator, Shell};
|
use clap_complete::{generate, Generator, Shell};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
|
|
||||||
use imgurs::api::configuration::ImgurHandle;
|
|
||||||
|
|
||||||
use crate::cli::{credits::*, delete_image::*, info_image::*, upload_image::*};
|
use crate::cli::{credits::*, delete_image::*, info_image::*, upload_image::*};
|
||||||
|
|
||||||
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
|
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::print_image_info;
|
|
||||||
use imgurs::api::{configuration::ImgurHandle, upload_image::upload_image as upload_img};
|
use imgurs::api::{configuration::ImgurHandle, upload_image::upload_image as upload_img};
|
||||||
|
|
||||||
|
use super::print_image_info;
|
||||||
|
|
||||||
use base64::encode as base64_encode;
|
use base64::encode as base64_encode;
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::{fs::read as fs_read, path::Path, process::exit};
|
use std::{fs::read as fs_read, path::Path, process::exit};
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
use dirs::config_dir;
|
|
||||||
use toml::from_str;
|
|
||||||
|
|
||||||
use super::Config;
|
use super::Config;
|
||||||
use log::{error, warn};
|
|
||||||
|
|
||||||
|
use dirs::config_dir;
|
||||||
|
use log::{error, warn};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{create_dir_all, read_to_string, File},
|
fs::{create_dir_all, read_to_string, File},
|
||||||
io::Write as _,
|
io::Write as _,
|
||||||
path::Path,
|
path::Path,
|
||||||
process::exit,
|
process::exit,
|
||||||
};
|
};
|
||||||
|
use toml::from_str;
|
||||||
|
|
||||||
pub fn parse() -> Config {
|
pub fn parse() -> Config {
|
||||||
toml().unwrap_or_else(|e| {
|
toml().unwrap_or_else(|e| {
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -2,18 +2,22 @@ mod cli;
|
||||||
mod config;
|
mod config;
|
||||||
|
|
||||||
use cli::parse::parse;
|
use cli::parse::parse;
|
||||||
|
|
||||||
use simple_logger::SimpleLogger;
|
|
||||||
|
|
||||||
use imgurs::api::ImgurHandle;
|
use imgurs::api::ImgurHandle;
|
||||||
|
|
||||||
|
use log::error;
|
||||||
|
use simple_logger::SimpleLogger;
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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 config = config::toml::parse();
|
||||||
|
|
||||||
let client = ImgurHandle::new((&config.imgur.id).to_string());
|
let client = ImgurHandle::new((&config.imgur.id).to_string());
|
||||||
|
|
||||||
parse(client).await;
|
parse(client).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue