mirror of
https://git.42l.fr/neil/sncf.git
synced 2024-05-02 22:13:10 +02:00
adding comments in config.rs
This commit is contained in:
parent
6a9465d579
commit
5bf70566ac
|
@ -24,6 +24,7 @@ lazy_static! {
|
||||||
pub static ref LOC: Value = init_lang();
|
pub static ref LOC: Value = init_lang();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open LOC_FILE and store it in memory (LOC)
|
||||||
fn init_lang() -> Value {
|
fn init_lang() -> Value {
|
||||||
let mut file = File::open(LOC_FILE).expect("init_lang: Can't open translations file");
|
let mut file = File::open(LOC_FILE).expect("init_lang: Can't open translations file");
|
||||||
let mut data = String::new();
|
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")
|
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<Path>) -> io::Result<Vec<String>> {
|
fn lines_from_file(filename: impl AsRef<Path>) -> io::Result<Vec<String>> {
|
||||||
BufReader::new(File::open(filename)?).lines().collect()
|
BufReader::new(File::open(filename)?).lines().collect()
|
||||||
}
|
}
|
||||||
|
@ -52,6 +54,7 @@ pub struct Config {
|
||||||
|
|
||||||
// totally not copypasted from rs-short
|
// totally not copypasted from rs-short
|
||||||
impl Config {
|
impl Config {
|
||||||
|
// open and parse CONFIG_FILE
|
||||||
pub fn init() -> Self {
|
pub fn init() -> Self {
|
||||||
let mut conffile = File::open(CONFIG_FILE).expect(
|
let mut conffile = File::open(CONFIG_FILE).expect(
|
||||||
r#"Config file config.toml not found.
|
r#"Config file config.toml not found.
|
||||||
|
@ -63,6 +66,9 @@ impl Config {
|
||||||
.expect("Couldn't read config to string");
|
.expect("Couldn't read config to string");
|
||||||
toml::from_str(&confstr).expect("Couldn't deserialize the config")
|
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) {
|
pub fn check_version(&self) {
|
||||||
if self.config_version != CONFIG_VERSION {
|
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);
|
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);
|
||||||
|
|
Loading…
Reference in a new issue