use std::path::PathBuf;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
mod copy;
mod error;
mod index;
mod info;
mod tiles;
mod validate;
#[derive(Parser)]
#[command(name = "gpkg", version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Info {
file: PathBuf,
},
Validate {
file: PathBuf,
#[arg(long)]
strict: bool,
},
Index {
file: PathBuf,
layer: String,
},
Repair {
file: PathBuf,
layer: Option<String>,
},
Copy {
src: PathBuf,
dst: PathBuf,
},
Tiles {
#[command(subcommand)]
command: TileCommand,
},
}
#[derive(Subcommand)]
enum TileCommand {
Info {
file: PathBuf,
pyramid: Option<String>,
},
Get {
file: PathBuf,
pyramid: String,
zoom: i64,
column: i64,
row: i64,
#[arg(long)]
out: Option<PathBuf>,
},
}
fn main() -> ExitCode {
let cli = Cli::parse();
let result = match cli.command {
Command::Info { file } => info::run(&file),
Command::Validate { file, strict } => validate::run(&file, strict),
Command::Index { file, layer } => index::build(&file, &layer),
Command::Repair { file, layer } => index::repair(&file, layer.as_deref()),
Command::Copy { src, dst } => copy::run(&src, &dst),
Command::Tiles { command } => match command {
TileCommand::Info { file, pyramid } => tiles::info(&file, pyramid.as_deref()),
TileCommand::Get {
file,
pyramid,
zoom,
column,
row,
out,
} => tiles::get(
&file,
&pyramid,
geopackage::core::tiles::TileCoord::new(zoom, column, row),
out.as_deref(),
),
},
};
match result {
Ok(code) => code,
Err(error) => {
eprintln!("gpkg: {error}");
ExitCode::FAILURE
}
}
}