Skip to main content

rusticity_term/
lib.rs

1pub mod apig;
2pub mod app;
3pub mod aws;
4pub mod cfn;
5pub mod cloudtrail;
6pub mod common;
7pub mod cw;
8pub mod ec2;
9pub mod ecr;
10pub mod event;
11pub mod iam;
12pub mod keymap;
13pub mod lambda;
14pub mod s3;
15pub mod session;
16pub mod sqs;
17pub mod table;
18pub mod ui;
19
20pub use app::{
21    App, DetailTab, EventColumn, EventFilterFocus, LogGroupColumn, Service, StreamSort, ViewMode,
22};
23pub use cw::insights::{DateRangeType, InsightsFocus, InsightsState, QueryLanguage, TimeUnit};
24use std::collections::HashMap;
25
26/// Initialize all services (i18n, etc.)
27pub fn init() {
28    // Load column customizations from config.toml
29    let mut i18n = HashMap::new();
30    if let Some(home) = std::env::var_os("HOME") {
31        let config_path = std::path::Path::new(&home)
32            .join(".config")
33            .join("rusticity")
34            .join("config.toml");
35
36        if let Ok(contents) = std::fs::read_to_string(&config_path) {
37            if let Ok(toml_map) = contents.parse::<toml::Table>() {
38                if let Some(columns_section) = toml_map.get("columns").and_then(|v| v.as_table()) {
39                    flatten_toml(columns_section, "column", &mut i18n);
40                }
41            }
42        }
43    }
44
45    // Initialize each service to populate their column defaults
46    apig::init(&mut i18n);
47    lambda::init(&mut i18n);
48    ec2::init(&mut i18n);
49    ecr::init(&mut i18n);
50    s3::init(&mut i18n);
51    cw::init(&mut i18n);
52    sqs::init(&mut i18n);
53    cfn::init(&mut i18n);
54    cloudtrail::init(&mut i18n);
55    iam::init(&mut i18n);
56
57    // Set shared i18n map after all defaults are added
58    common::set_i18n(i18n);
59}
60
61fn flatten_toml(
62    table: &toml::Table,
63    prefix: &str,
64    map: &mut std::collections::HashMap<String, String>,
65) {
66    for (key, value) in table {
67        let full_key = format!("{}.{}", prefix, key);
68        match value {
69            toml::Value::String(s) => {
70                map.insert(full_key, s.clone());
71            }
72            toml::Value::Table(t) => {
73                flatten_toml(t, &full_key, map);
74            }
75            _ => {}
76        }
77    }
78}
79
80pub use event::EventHandler;
81pub use session::Session;