Skip to content

Commit

Permalink
Fixed clippy lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
RRArny committed Nov 17, 2024
1 parent 36aae0d commit f236d41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 17 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Config {
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::io::BufReader;

use api::request_wx;
use clap::Parser;
use colored::ColoredString;

mod metar;
use metar::Metar;
Expand All @@ -25,7 +24,6 @@ mod position;
mod api;

mod config;
use config::get_config;
use config::Config;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f236d41

Please sign in to comment.