Moving logic to current_weather_printer for better testing
This commit is contained in:
+16
-48
@@ -1,6 +1,7 @@
|
||||
mod cli;
|
||||
mod coords;
|
||||
|
||||
mod current_weater_print_params;
|
||||
mod current_weather;
|
||||
mod current_weather_printer;
|
||||
mod ifconfig;
|
||||
@@ -8,6 +9,7 @@ mod ip_api;
|
||||
mod open_meteo;
|
||||
|
||||
use billboard::{Alignment, Billboard};
|
||||
use current_weater_print_params::CurrentWeatherPrintParams;
|
||||
use std::process::exit;
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -91,61 +93,27 @@ fn main() {
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let mut string_vec: Vec<String> = Vec::new();
|
||||
|
||||
if !clean {
|
||||
let mut title_header: Vec<String> = Vec::new();
|
||||
title_header.push(String::from("=== Current weather"));
|
||||
|
||||
if (all || include_city) && city.is_some() {
|
||||
title_header.push(String::from("for"));
|
||||
title_header.push(city.unwrap());
|
||||
}
|
||||
|
||||
title_header.push(String::from("==="));
|
||||
string_vec.push(title_header.join(" "));
|
||||
} else {
|
||||
if all || include_coords {
|
||||
string_vec.push(coordinates.latitude.to_string());
|
||||
string_vec.push(coordinates.longitude.to_string());
|
||||
}
|
||||
if (all || include_city) && city.is_some() {
|
||||
string_vec.push(city.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
let current_weather_printer = CurrentWeatherPrinter::new(current_weather, clean);
|
||||
if is_day || all {
|
||||
string_vec.push(current_weather_printer.extract_day());
|
||||
}
|
||||
if temperature || all {
|
||||
string_vec.push(current_weather_printer.extract_temperature());
|
||||
}
|
||||
if windspeed || all {
|
||||
string_vec.push(current_weather_printer.extract_wind_speed());
|
||||
}
|
||||
if winddirection || all {
|
||||
string_vec.push(current_weather_printer.extract_wind_direction());
|
||||
}
|
||||
|
||||
if !clean && (all || include_coords) {
|
||||
string_vec.push(format!(
|
||||
"Latitude: {}, Longitude: {}",
|
||||
coordinates.latitude, coordinates.longitude
|
||||
));
|
||||
}
|
||||
let print_params = CurrentWeatherPrintParams::new(
|
||||
all,
|
||||
is_day,
|
||||
temperature,
|
||||
windspeed,
|
||||
winddirection,
|
||||
include_coords,
|
||||
include_city,
|
||||
clean,
|
||||
);
|
||||
|
||||
let current_weather_printer = CurrentWeatherPrinter::new(current_weather, print_params, coordinates, city);
|
||||
let output = current_weather_printer.extract_string();
|
||||
if clean {
|
||||
let final_string = string_vec.join(",");
|
||||
println!("{final_string}");
|
||||
println!("{output}");
|
||||
} else {
|
||||
string_vec.push(String::from("=== Weather data by Open-Meteo.com ==="));
|
||||
let final_string = string_vec.join("\n");
|
||||
Billboard::builder()
|
||||
.text_alignment(Alignment::Left)
|
||||
.box_alignment(Alignment::Left)
|
||||
.build()
|
||||
.eprint(final_string);
|
||||
.eprint(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user