Ini File could be parsed
This commit is contained in:
		| @@ -23,3 +23,5 @@ serde_json = "1.0" | |||||||
| # end of web stuff | # end of web stuff | ||||||
| ping = "0.4.1" | ping = "0.4.1" | ||||||
| paho-mqtt = "0.12.3" | paho-mqtt = "0.12.3" | ||||||
|  | # Ini File parser | ||||||
|  | rust-ini = "0.21" | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ use std::io; | |||||||
| use std::process::ExitCode; | use std::process::ExitCode; | ||||||
| use openweathermap::forecast::Forecast; | use openweathermap::forecast::Forecast; | ||||||
| use straba::NextDeparture; | use straba::NextDeparture; | ||||||
|  | use ini::Ini; | ||||||
| // This declaration will look for a file named `straba.rs` and will | // This declaration will look for a file named `straba.rs` and will | ||||||
| // insert its contents inside a module named `straba` under this scope | // insert its contents inside a module named `straba` under this scope | ||||||
| mod straba; | mod straba; | ||||||
| @@ -397,7 +398,19 @@ struct Message { | |||||||
|     string: Option<String> |     string: Option<String> | ||||||
| } | } | ||||||
|  |  | ||||||
| fn main_function(ipaddress: String, mqtt: Option<String>) -> ExitCode { | fn main_function(ipaddress: String, mqtt: Option<String>, config: Option<String>) -> ExitCode { | ||||||
|  |  | ||||||
|  |     // Read configuration file | ||||||
|  |     if config.is_some() { | ||||||
|  |         let i = Ini::load_from_file(config.clone().unwrap()).unwrap(); | ||||||
|  |         for (sec, prop) in i.iter() { | ||||||
|  |             println!("Section: {:?}", sec); | ||||||
|  |             for (k, v) in prop.iter() { | ||||||
|  |                 println!("{}:{}", k, v); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let mut device_online = check_connection(ipaddress.clone()); |     let mut device_online = check_connection(ipaddress.clone()); | ||||||
|     if !device_online { |     if !device_online { | ||||||
|         println!("{:} not online", &ipaddress); |         println!("{:} not online", &ipaddress); | ||||||
| @@ -542,13 +555,26 @@ fn main() -> ExitCode { | |||||||
|         // one argument passed |         // one argument passed | ||||||
|         2 => { |         2 => { | ||||||
|             let ip = &args[1]; |             let ip = &args[1]; | ||||||
|             return main_function(ip.to_string(), None); |             return main_function(ip.to_string(), None, None); | ||||||
|         } |         } | ||||||
|         // two argument passed |         // two argument passed | ||||||
|         3 => { |         3 => { | ||||||
|             let ip = &args[1]; |             let ip = &args[1]; | ||||||
|             let mqtt = &args[2]; |             let mqtt = &args[2]; | ||||||
|             return main_function(ip.to_string(), Some(mqtt.to_string())); |             return main_function(   ip.to_string(), | ||||||
|  |                                     Some(mqtt.to_string()), | ||||||
|  |                                     None | ||||||
|  |                                 ); | ||||||
|  |         } | ||||||
|  |         // three argument passed | ||||||
|  |         4 => { | ||||||
|  |             let ip = &args[1]; | ||||||
|  |             let mqtt = &args[2]; | ||||||
|  |             let config = &args[3]; | ||||||
|  |             return main_function(   ip.to_string(), | ||||||
|  |                                     Some(mqtt.to_string()), | ||||||
|  |                                     Some(config.to_string()) | ||||||
|  |                                 ); | ||||||
|         } |         } | ||||||
|         // all the other cases |         // all the other cases | ||||||
|         _ => { |         _ => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user