1use std::time::Duration;
4
5#[derive(Debug, Clone)]
7pub struct Config {
8 pub daemon_url: String,
10 pub verbosity: String,
12 pub max_retries: u32,
14 pub daemon_ready_timeout: Duration,
16 pub loop_status_timeout: Duration,
18 pub subscription_timeout: Duration,
20}
21
22impl Default for Config {
23 fn default() -> Self {
24 Self {
25 daemon_url: "ws://127.0.0.1:8765".into(),
26 verbosity: String::new(),
27 max_retries: 40,
28 daemon_ready_timeout: Duration::from_secs(20),
29 loop_status_timeout: Duration::from_secs(30),
30 subscription_timeout: Duration::from_secs(30),
31 }
32 }
33}
34
35pub fn load_config_from_env() -> Config {
37 let mut cfg = Config::default();
38 if let Ok(url) = std::env::var("SOOTHE_WS_URL") {
39 if !url.trim().is_empty() {
40 cfg.daemon_url = url.trim().to_string();
41 }
42 } else if let Ok(url) = std::env::var("SOOTHE_DAEMON_URL") {
43 if !url.trim().is_empty() {
44 cfg.daemon_url = url.trim().to_string();
45 }
46 }
47 if let Ok(v) = std::env::var("SOOTHE_VERBOSITY") {
48 cfg.verbosity = v;
49 }
50 if let Ok(v) = std::env::var("SOOTHE_MAX_RETRIES") {
51 if let Ok(n) = v.parse() {
52 cfg.max_retries = n;
53 }
54 }
55 if let Ok(v) = std::env::var("SOOTHE_DAEMON_READY_TIMEOUT_SEC") {
56 if let Ok(n) = v.parse::<u64>() {
57 cfg.daemon_ready_timeout = Duration::from_secs(n);
58 }
59 }
60 if let Ok(v) = std::env::var("SOOTHE_LOOP_STATUS_TIMEOUT_SEC") {
61 if let Ok(n) = v.parse::<u64>() {
62 cfg.loop_status_timeout = Duration::from_secs(n);
63 }
64 }
65 if let Ok(v) = std::env::var("SOOTHE_SUBSCRIPTION_TIMEOUT_SEC") {
66 if let Ok(n) = v.parse::<u64>() {
67 cfg.subscription_timeout = Duration::from_secs(n);
68 }
69 }
70 cfg
71}