mirror of
https://github.com/OMGeeky/backup_config.git
synced 2026-01-09 05:00:57 +01:00
add default builder method
This commit is contained in:
12
Cargo.toml
12
Cargo.toml
@@ -1,10 +1,18 @@
|
||||
[package]
|
||||
name = "twba-backup-config"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
confique = { version = "0.2" , features= ["json5","toml"]}
|
||||
confique = { version = "0.2", features = ["json5", "toml"] }
|
||||
tracing = { version = "0.1", optional = true }
|
||||
shellexpand = { version = "3.1", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["tracing", "env", "home"]
|
||||
env = []
|
||||
tracing = ["dep:tracing"]
|
||||
home = ["dep:shellexpand"]
|
||||
|
||||
23
src/lib.rs
23
src/lib.rs
@@ -127,3 +127,26 @@ pub struct Twitch {
|
||||
#[config(default = 50)]
|
||||
pub downloader_thread_count: u64,
|
||||
}
|
||||
|
||||
pub fn get_default_builder() -> confique::Builder<Conf> {
|
||||
#[cfg(feature = "tracing")]
|
||||
tracing::info!("building default config");
|
||||
let conf = Conf::builder();
|
||||
#[cfg(feature = "env")]
|
||||
let conf = conf.env().file(
|
||||
std::env::var("TWBA_CONFIG")
|
||||
.map(|v| {
|
||||
#[cfg(feature = "tracing")]
|
||||
tracing::info!("using '{}' as primary config source after env", v);
|
||||
v
|
||||
})
|
||||
.unwrap_or_else(|_| {
|
||||
#[cfg(feature = "tracing")]
|
||||
tracing::warn!("could not get config location from env");
|
||||
"./settings.toml".to_string()
|
||||
}),
|
||||
);
|
||||
#[cfg(feature = "home")]
|
||||
let conf = conf.file(shellexpand::tilde("~/twba/config.toml").into_owned());
|
||||
conf
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user