Adding format to select between normal, clean and JSON. This needs some refactor

This commit is contained in:
2023-06-13 18:38:32 +02:00
parent 9978e1553b
commit 8a3e5783c2
10 changed files with 507 additions and 306 deletions
+22 -9
View File
@@ -1,8 +1,12 @@
mod cli;
mod coords;
mod current_weather;
mod current_weather_extractor;
mod current_weather_output;
mod current_weather_output_model;
mod current_weather_print_params;
mod current_weather_printer;
mod data_format;
mod ifconfig;
mod ip_api;
mod open_meteo;
@@ -11,13 +15,14 @@ mod temp_unit;
use billboard::{Alignment, Billboard};
use current_weather_print_params::CurrentWeatherPrintParams;
use data_format::DataFormat;
use std::process::exit;
use structopt::StructOpt;
use cli::Arguments;
use coords::Coordinates;
use current_weather_printer::CurrentWeatherPrinter;
use current_weather_extractor::CurrentWeatherExtractor;
use ifconfig::extract_public_ip;
use ip_api::extract_coords_and_city;
use open_meteo::request_current_weather;
@@ -37,7 +42,9 @@ fn main() {
winddirection,
include_coords,
include_city,
mut format,
clean,
json,
} => {
if !all
&& !is_day
@@ -96,6 +103,12 @@ fn main() {
exit(1);
});
if clean {
format = DataFormat::Clean;
} else if json {
format = DataFormat::JSON;
}
let print_params = CurrentWeatherPrintParams::new(
all,
is_day,
@@ -106,20 +119,20 @@ fn main() {
winddirection,
include_coords,
include_city,
clean,
format,
);
let current_weather_printer =
CurrentWeatherPrinter::new(current_weather, print_params, coordinates, city);
let output = current_weather_printer.extract_string();
if clean {
println!("{output}");
} else {
CurrentWeatherExtractor::new(current_weather, print_params, coordinates, city);
let output = current_weather_printer.extract_output();
if DataFormat::Normal == current_weather_printer.params.format {
Billboard::builder()
.text_alignment(Alignment::Left)
.box_alignment(Alignment::Left)
.build()
.eprint(output);
.eprint(output.to_string());
} else {
println!("{}", output.to_string());
}
}
}