mirror of https://github.com/MedzikUser/imgurs
add create default config if not exist, create CHANGELOG.md
This commit is contained in:
parent
93ffaaed5d
commit
ee7293791c
|
@ -96,6 +96,14 @@ jobs:
|
|||
shell: bash
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
|
||||
- name: Get CHANGELOG.md entry
|
||||
id: changelog_reader
|
||||
uses: mindsers/changelog-reader-action@v1
|
||||
with:
|
||||
version: ${{ steps.tag_name.outputs.current_version }}
|
||||
path: ./CHANGELOG.md
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
|
||||
- name: Publish
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
<!-- next-header -->
|
||||
|
||||
## [Unreleased]
|
||||
### CLI
|
||||
- create default config
|
||||
|
||||
### Library
|
||||
- rustls
|
||||
|
||||
## [0.0.1] - 2022-01-23
|
||||
### CLI
|
||||
- commands
|
||||
- credits
|
||||
- delete
|
||||
- info
|
||||
- upload
|
||||
- toml config parser
|
||||
|
||||
### Library
|
||||
- image info
|
||||
- rate limit
|
||||
- image info
|
||||
- delete image
|
||||
- upload image
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.0.1...HEAD
|
||||
[0.0.1]: https://github.com/MedzikUser/imgurs/commits/v0.0.1
|
|
@ -0,0 +1,2 @@
|
|||
[imgur]
|
||||
id = '3e3ce0d7ac14d56'
|
|
@ -6,7 +6,7 @@ use serde_derive::{Deserialize, Serialize};
|
|||
pub struct RateLimitInfo {
|
||||
pub data: RateLimitData,
|
||||
pub success: bool,
|
||||
pub status: i8,
|
||||
pub status: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct ConfigImgur {
|
|||
|
||||
pub fn parse() -> Result<Config, String> {
|
||||
let config_dir = config_dir().unwrap();
|
||||
let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgur/config.toml";
|
||||
let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgurs/config.toml";
|
||||
|
||||
let toml_str = read_to_string(file_dir).map_err(|err| err.to_string())?;
|
||||
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -3,9 +3,13 @@ mod config;
|
|||
|
||||
use cli::parse::parse;
|
||||
|
||||
use log::error;
|
||||
use dirs::config_dir;
|
||||
use log::warn;
|
||||
use simple_logger::SimpleLogger;
|
||||
use std::process::exit;
|
||||
use std::{path::Path, fs::create_dir_all};
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Write as _;
|
||||
|
||||
use imgurs::api::ImgurHandle;
|
||||
|
||||
|
@ -14,8 +18,22 @@ async fn main() {
|
|||
SimpleLogger::new().init().unwrap();
|
||||
|
||||
let config = config::toml::parse().unwrap_or_else(|error| {
|
||||
error!("Parse toml config: {}", error);
|
||||
exit(1);
|
||||
warn!("Parse toml config: {}! Creating config file...", error);
|
||||
|
||||
let default_config = include_str!(concat!("../config.toml"));
|
||||
|
||||
let sys_config_dir = config_dir().unwrap();
|
||||
let config_dir = format!("{}/imgurs/config.toml", sys_config_dir.to_string_lossy());
|
||||
let config_path = Path::new(&config_dir);
|
||||
|
||||
let prefix = config_path.parent().unwrap();
|
||||
create_dir_all(prefix).unwrap();
|
||||
|
||||
let mut file_ref = File::create(config_path).expect("create failed");
|
||||
|
||||
file_ref.write_all(default_config.as_bytes()).expect("failed write default config to file");
|
||||
|
||||
config::toml::parse().unwrap()
|
||||
});
|
||||
|
||||
let client = ImgurHandle::new((&config.imgur.id).to_string());
|
||||
|
|
Loading…
Reference in New Issue