use std::env;
use anyhow::Result;
use clap::{CommandFactory, Parser};
use umbrella::Weatherstack;
#[derive(Parser)]
struct Args {
#[arg(short, long, env = "WEATHERSTACK_API_KEY", required = true)]
api_key: String,
#[arg(short, long)]
fahrenheit: bool,
#[arg(required = true)]
location: Vec<String>,
}
fn main() -> Result<()> {
if env::args().count() < 2 {
Args::command().print_long_help()?;
return Ok(());
}
let args = Args::parse();
let location = args.location.join(" ");
let ws = Weatherstack::new(&args.api_key);
let weather = ws.get_weather(&location)?;
println!(
"{} {} ({})",
weather.summary,
if args.fahrenheit {
format!("{:.1}ºF", weather.temperature.as_fahrenheit())
} else {
format!("{:.1}ºC", weather.temperature.as_celsius())
},
weather.location,
);
Ok(())
}