diff --git a/src/config.rs b/src/config.rs index b5bd45d..3e18ef0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,25 +56,27 @@ impl Default for Config { } } -pub async fn get_config(secrets: &Secrets, args: &Args) -> Config { - let mut config: Config = read_config_file(args.config_file.clone()); - - if let Some(icao) = args.airfield.clone() { - config.position = Position::Airfield(icao.clone()); - } else if let Some(lat) = args.latitude { - if let Some(long) = args.longitude { - config.position = Position::LatLong(LatLong(lat, long)); +impl Config { + pub async fn get_config(secrets: &Secrets, args: &Args) -> Config { + let mut config: Config = read_config_file(args.config_file.clone()); + + if let Some(icao) = args.airfield.clone() { + config.position = Position::Airfield(icao.clone()); + } else if let Some(lat) = args.latitude { + if let Some(long) = args.longitude { + config.position = Position::LatLong(LatLong(lat, long)); + } + println!("Please provide both Latitude and Longitude. Defaulting to geoip..."); } - println!("Please provide both Latitude and Longitude. Defaulting to geoip..."); - } - if let Position::Airfield(ref icao) = config.position { - if !check_icao_code(icao, secrets).await { - println!("Invalid airfield {icao}. Defaulting to geoip..."); - config.position = Position::GeoIP; + if let Position::Airfield(ref icao) = config.position { + if !check_icao_code(icao, secrets).await { + println!("Invalid airfield {icao}. Defaulting to geoip..."); + config.position = Position::GeoIP; + } } + config } - config } fn read_config_file(config_filepath: Option) -> Config { diff --git a/src/main.rs b/src/main.rs index 6a94087..7577d0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ use std::io::BufReader; use api::request_wx; use clap::Parser; -use colored::ColoredString; mod metar; use metar::Metar; @@ -25,7 +24,6 @@ mod position; mod api; mod config; -use config::get_config; use config::Config; #[derive(Parser, Debug)] @@ -79,7 +77,7 @@ fn get_weather_from_file(filename: String, config: &Config) -> Metar { async fn main() { let args = Args::parse(); let secrets = get_secrets(args.key.clone()); - let config = get_config(&secrets, &args).await; + let config = Config::get_config(&secrets, &args).await; let metar = match args.file { Some(filename) => get_weather_from_file(filename, &config), None => get_weather(&config, &secrets).await,