geolite 0.0.14

open source geocode solution
use std::io::Write;

use crate::interfaces::cli::exec::stages::stage;

pub fn command_handler_extract_osm_pbf_header(
  data_path: &str,
  sqlite_path: &str,
  inputs: &[String],
) {
  let conn = crate::database::open_write(sqlite_path);
  let file = crate::osm_pbf_file::osm_pbf_file::open(Some(&conn), data_path);

  for (i, input) in inputs.iter().enumerate() {
    let Some(resolved) = super::resolve_input(&conn, data_path, i, input) else {
      continue;
    };
    stage::extract_osm_pbf_header.require(&conn, Some(&resolved));
    let fname = &resolved.name;

    print!("\x1b[1;32mextracting\x1b[0m header from {fname}...");
    let _ = std::io::stdout().flush();

    let hdr = file.extract_osm_header(&resolved.path);

    println!(" done");

    if let Some(bbox) = &hdr.bbox {
      println!(
        "\x1b[1;32mbbox\x1b[0m       {:.4},{:.4}  {:.4},{:.4}",
        bbox.left, bbox.bottom, bbox.right, bbox.top
      );
    }
    if let Some(p) = &hdr.writingprogram {
      println!("\x1b[1;32mprogram\x1b[0m    {p}");
    }
    if let Some(s) = &hdr.source {
      println!("\x1b[1;32msource\x1b[0m     {s}");
    }
    if let Some(ts) = hdr.replication_timestamp {
      println!("\x1b[1;32mreplicated\x1b[0m {ts}");
    }
  }
}