feat: 添加配置目录环境变量 (#632)
* feat: 添加配置目录环境变量 * feat: 添加配置目录命令行参数 * feat: 添加配置目录短参数 * refactor: 调整一下写法 --------- Co-authored-by: amtoaer <amtoaer@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use clap::Parser;
|
||||
@@ -16,6 +17,9 @@ pub struct Args {
|
||||
|
||||
#[arg(short, long, env = "DISABLE_CREDENTIAL_REFRESH")]
|
||||
pub disable_credential_refresh: bool,
|
||||
|
||||
#[arg(short, long, env = "BILI_SYNC_CONFIG_DIR")]
|
||||
pub config_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
mod built_info {
|
||||
|
||||
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
use crate::bilibili::{Credential, DanmakuOption, FilterOption};
|
||||
use crate::config::args::ARGS;
|
||||
use crate::config::default::{
|
||||
default_auth_token, default_bind_address, default_collection_path, default_favorite_path, default_submission_path,
|
||||
default_time_format,
|
||||
@@ -16,8 +17,12 @@ use crate::config::item::{ConcurrentLimit, NFOTimeType, SkipOption, Trigger};
|
||||
use crate::notifier::Notifier;
|
||||
use crate::utils::model::{load_db_config, save_db_config};
|
||||
|
||||
pub static CONFIG_DIR: LazyLock<PathBuf> =
|
||||
LazyLock::new(|| dirs::config_dir().expect("No config path found").join("bili-sync"));
|
||||
pub static CONFIG_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
ARGS.config_dir
|
||||
.clone()
|
||||
.or_else(|| dirs::config_dir().map(|dir| dir.join("bili-sync")))
|
||||
.expect("No config path found")
|
||||
});
|
||||
|
||||
#[derive(Serialize, Deserialize, Validate, Clone)]
|
||||
pub struct Config {
|
||||
|
||||
Reference in New Issue
Block a user