extern crate weather;
#[macro_use]
extern crate clap;
use weather::wunderground::*;
use std::error::Error;
use std::fmt::Display;
static WUNDERGROUND_ABOUT: &'static str = "Wunderground weather source, requires WUNDERGROUND_ACCESS_TOKEN and WUNDERGROUND_LOCATION environment variables to be set";
fn main() {
let matches = clap_app!(weather =>
(version: crate_version!())
(about: "Weather forecasting CLI tool")
(setting: clap::AppSettings::SubcommandRequiredElseHelp)
(@subcommand w =>
(about: WUNDERGROUND_ABOUT)
(@arg current: -c "Current conditions")
(@arg hourly: -o "Hourly forecast"))
).get_matches();
if let Some(matches) = matches.subcommand_matches("w") {
let wunderground = Wunderground::new(None);
if matches.is_present("hourly") {
print_forecast(wunderground.hourly_forecast());
} else {
print_forecast(wunderground.current_conditions());
}
}
}
fn print_forecast<T: Display>(forecast: Result<T, Box<Error>>) {
match forecast {
Ok(forecast) => println!("{}", forecast),
Err(err) => println!("{}", err)
}
}