1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use serde::{Deserialize, Serialize};
use crate::{download::DownloadParams, compare::CompareParams};
#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
pub struct Config {
pub flex_query_id: String,
pub ib_token: String,
pub flex_report_path: Option<String>,
pub flex_reports_dir: Option<String>,
pub ledger_init_file: Option<String>,
pub symbols_path: String
}
pub fn get_dl_config(params: DownloadParams) -> Config {
let mut cfg = read_config_file(None);
if let Some(query_id) = params.query_id {
cfg.flex_query_id = query_id.to_string();
} else if let Ok(env_queryid) = std::env::var("IBFLEX_QUERYID") {
cfg.flex_query_id = env_queryid;
};
if let Some(token) = params.token {
cfg.ib_token = token;
} else if let Ok(env_tkn) = std::env::var("IBFLEX_TOKEN") {
cfg.ib_token = env_tkn;
};
cfg
}
pub fn get_cmp_config(params: &CompareParams) -> Config {
let mut cfg = match ¶ms.config_path {
Some(cfg_path) => read_config_file(Some(cfg_path.to_owned())),
None => read_config_file(None),
};
if let Some(flex_report_path) = ¶ms.flex_report_path {
cfg.flex_report_path = Some(flex_report_path.to_owned());
}
if let Some(flex_reports_dir) = ¶ms.flex_reports_dir {
cfg.flex_reports_dir = Some(flex_reports_dir.to_owned());
}
if let Some(ledger_init_file) = ¶ms.ledger_init_file {
cfg.ledger_init_file = Some(ledger_init_file.to_owned());
}
if let Some(symbols_path) = ¶ms.symbols_path {
cfg.symbols_path = symbols_path.to_string();
}
cfg
}
pub fn read_config_file(cfg_path: Option<String>) -> Config {
let path = match cfg_path {
Some(given_path) => given_path.to_owned(),
None => "./ibflex.toml".to_owned(),
};
confy::load_path(path).expect("configuration loaded")
}