Skip to content

Commit 215ca81

Browse files
authored
feat: impl dynamic load configuration (#2)
* feat: impl dynamic load configuration * chore: delete tests and add Cargo env * ci: fix clippy error
1 parent 59d77f8 commit 215ca81

File tree

10 files changed

+1086
-23
lines changed

10 files changed

+1086
-23
lines changed

Cargo.lock

Lines changed: 203 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ path = "src/main.rs"
1111
anyhow = "1.0"
1212
chrono = "0.4"
1313
dialoguer = "0.11"
14-
console = "0.15"
14+
console = "0.16.0"
1515
wait-timeout = "0.2.1"
16+
toml = "0.9.2"
17+
serde = { version = "1.0", features = ["derive"] }
18+
dirs = "6.0.0"

src/config.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::config_loader;
12
use crate::error::{CliError, Result};
23
use std::env;
34
use std::path::PathBuf;
@@ -29,9 +30,20 @@ impl Default for Config {
2930
}
3031

3132
impl Config {
32-
/// Creates a new configuration instance from environment variables
33+
/// Creates a new configuration instance from dynamic config loader
34+
/// or falls back to environment variables if that fails
3335
pub fn new() -> Self {
34-
let mut config = Self::default();
36+
// Try to load configuration dynamically, fall back to default if it fails
37+
let mut config = config_loader::load_config()
38+
.map(config_loader::to_app_config)
39+
.unwrap_or_else(|e| {
40+
eprintln!(
41+
"\x1b[31m Warning: Failed to load dynamic configuration: {e}. Using default configuration.\x1b[0m"
42+
);
43+
Self::default()
44+
});
45+
46+
// Allow environment variables to override config
3547
config.load_from_env();
3648
config
3749
}

0 commit comments

Comments
 (0)