diff --git a/src/config.rs b/src/config.rs index 8b7a2b6..98da773 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ lazy_static! { pub static ref LOC: Value = init_lang(); } +// Open LOC_FILE and store it in memory (LOC) fn init_lang() -> Value { let mut file = File::open(LOC_FILE).expect("init_lang: Can't open translations file"); let mut data = String::new(); @@ -32,6 +33,7 @@ fn init_lang() -> Value { serde_json::from_str(&data).expect("init_lang(): Can't parse translations file") } +// Open a file from its path fn lines_from_file(filename: impl AsRef) -> io::Result> { BufReader::new(File::open(filename)?).lines().collect() } @@ -52,6 +54,7 @@ pub struct Config { // totally not copypasted from rs-short impl Config { + // open and parse CONFIG_FILE pub fn init() -> Self { let mut conffile = File::open(CONFIG_FILE).expect( r#"Config file config.toml not found. @@ -63,6 +66,9 @@ impl Config { .expect("Couldn't read config to string"); toml::from_str(&confstr).expect("Couldn't deserialize the config") } + + // if config.config_version doesn't match the hardcoded version, + // ask the admin to manually upgrade its config file pub fn check_version(&self) { if self.config_version != CONFIG_VERSION { eprintln!("Your configuration file is obsolete!\nPlease update it following the instructions in https://git.42l.fr/neil/sncf/wiki/Upgrade-from-a-previous-version and update its version to {}.", CONFIG_VERSION);