overpass 0.1.0

Query OpenStreetMap Nodes
Documentation
use clap::{Parser, Subcommand};
use overpass::{BoundingBox, Config};

#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
    #[clap(short, long, env)]
    url: String,

    #[clap(short, long, env)]
    key: String,

    #[clap(short, long, env)]
    val: String,

    #[command(subcommand)]
    cmd: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Construct a bounding box from its coordinate boundaries
    #[allow(clippy::upper_case_acronyms)]
    BBOX {
        /// Minimum Longitude (left)
        #[clap(long)]
        xmin: f64,
        /// Minimum Latitude (bottom)
        #[clap(long)]
        ymin: f64,
        /// Maximum Longitude (right)
        #[clap(long)]
        xmax: f64,
        /// Maximum Latitude (top)
        #[clap(long)]
        ymax: f64,
    },
    /// Construct a bounding box around a center point
    Point {
        /// Latitude
        #[clap(long)]
        lat: f64,
        /// Longitude
        #[clap(long)]
        lon: f64,
        /// distance (km)
        #[clap(long)]
        d: f64,
    },
}

#[tokio::main]
async fn main() {
    let args = Args::parse();
    let c = Config {
        url: &args.url,
        timeout: 25,
        key: &args.key,
        val: &args.val,
    };
    let b = match args.cmd {
        Commands::BBOX {
            xmin,
            ymin,
            xmax,
            ymax,
        } => BoundingBox {
            xmin,
            ymin,
            xmax,
            ymax,
        },
        Commands::Point { lat, lon, d } => BoundingBox::from_point(lat, lon, d),
    };

    match b.search(&c).await {
        Ok(resp) => println!("{}", serde_json::to_string(&resp).unwrap()),
        Err(e) => eprintln!("Empty Query: {e}"),
    };
}