A simple command-line interface (CLI) application for retrieving weather information.
This project serves as a demonstration for the clap and reqwest crates.
- Get weather information for a specific zipcode
- Login and logout functionality (TODO)
To install the Weather CLI, make sure you have Rust and Cargo installed on your system. Then, clone the repository and build the project:
git clone https://github.com/0xsouravm/weather-cli.git
cd weather-cli
cargo build --release
cargo install --path .
export PATH="$HOME/.cargo/bin:$PATH"
To get weather information for a specific zipcode:
weather <zipcode>
Replace with the ISO 3166 zipcode for which you want to retrieve weather information. Ex - E14,GB (London)
To log in to the weather service:
weather login
To log out from the weather service:
weather logout
The application uses environment variables for configuration. Create a .env file in the project root directory with the following variables:
GEOCODER_API_URL="http://api.openweathermap.org/geo/1.0/zip?zip={zip}&appid={api_key}"
WEATHER_API_URL="https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={long}&appid={api_key}"
OPEN_WEATHER_API_KEY=<your_api_key>
Replace the placeholder with your actual API key.
main.rs
: Contains the main application logic and CLI structuretypes.rs
: Defines the types used in the applicationapi.rs
: Handles API requests to the weather and geocoding servicesenv.rs
: Exposes functions to fetch environment variablescli.rs
: Implements CLI-specific functionalityimpl.rs
: Contains additional implementation details to display the data