use std::error::Error;
use super::Command;
use crate::weather_api::{Client, WeatherUnit};
use clap::Parser;
#[derive(Parser, Debug)]
pub struct WeatherCommand {
#[clap()]
location: String,
#[clap(short, long, default_value = "imperial")]
unit: WeatherUnit,
}
impl WeatherCommand {
pub fn run(&self, command: &Command) -> Result<(), Box<dyn Error>> {
let client = Client::new()
.with_unit(self.unit.clone())
.login(command.key.clone());
let weather_result = client.get_weather_at_string_loc(&self.location)?;
println!("{}", weather_result.generate_weather_report());
Ok(())
}
}