use std::path::PathBuf;
use clap::Parser;
use crate::config::Config;
use crate::terrain::TerrainEncoding;
const VERB_TERRAIN: &str = "terrain";
const VERB_SPLAT_TILES: &str = "splat-tiles";
const VERB_RASTER: &str = "raster";
const VERB_RECONSTRUCT: &str = "reconstruct";
const VERB_DATASET: &str = "dataset";
const VERB_NOTICES: &str = "notices";
pub const NOTICE: &str = include_str!("../NOTICE.md");
pub const LONG_VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
"\n© geolith. Source-available under the FSL-1.1-ALv2 (LICENSE.md).\n",
"Outputs carry the credit \"© geolith\" after the attribution of their data.\n",
"Run `geolith notices` for the notices of third-party code and data."
);
#[derive(Debug, Parser)]
#[command(
name = "geolith terrain",
about = "GeoTIFF DEM → Terrain-RGB PMTiles",
version
)]
pub struct TerrainArgs {
#[arg(long, required = true)]
pub dem: Vec<PathBuf>,
#[arg(long)]
pub clip: Option<PathBuf>,
#[arg(long, short)]
pub output: PathBuf,
#[arg(long, default_value = "mapbox")]
pub encoding: String,
#[arg(long, default_value = "0")]
pub min_zoom: u8,
#[arg(long, default_value = "14")]
pub max_zoom: u8,
#[arg(long, default_value = "512")]
pub tile_size: u32,
#[arg(long)]
pub dem_crs: Option<u32>,
#[arg(long, default_value = "terrain")]
pub name: String,
}
#[derive(Debug, Parser)]
#[command(
name = "geolith splat-tiles",
about = "3DGS PLY → OGC 3D Tiles (KHR_gaussian_splatting + spz_2)",
version
)]
pub struct SplatTilesArgs {
#[arg(long)]
pub ply: PathBuf,
#[arg(long, short)]
pub output: PathBuf,
#[arg(long, allow_hyphen_values = true)]
pub longitude: f64,
#[arg(long, allow_hyphen_values = true)]
pub latitude: f64,
#[arg(long, default_value = "0", allow_hyphen_values = true)]
pub altitude: f64,
#[arg(long, default_value = "100000")]
pub max_splats_per_tile: usize,
#[arg(long, default_value = "6")]
pub max_depth: u8,
#[arg(long, default_value = "64")]
pub root_geometric_error: f64,
#[arg(long, default_value = "false")]
pub antialiased: bool,
#[arg(long, default_value = "true")]
pub emit_scene_spz: bool,
#[arg(long, default_value = "0")]
pub crop_percentile: f64,
#[arg(long, default_value = "1")]
pub scale: f32,
#[arg(long, default_value = "0")]
pub coverage_boost_scale: f32,
}
#[derive(Debug, Parser)]
#[command(
name = "geolith raster",
about = "XYZ/WMTS raster tiles -> PMTiles basemap archive",
version
)]
pub struct RasterArgs {
#[arg(long)]
pub url_template: String,
#[arg(long, short)]
pub output: PathBuf,
#[arg(long, default_value = "0")]
pub min_zoom: u8,
#[arg(long, default_value = "8")]
pub max_zoom: u8,
#[arg(long)]
pub bbox: Option<String>,
#[arg(long, default_value = "0")]
pub bbox_min_zoom: u8,
#[arg(long, default_value = "jpeg")]
pub format: String,
#[arg(long, default_value = "8")]
pub concurrency: usize,
#[arg(long, default_value = "50")]
pub request_delay_ms: u64,
#[arg(long, default_value = "5")]
pub attempts: u32,
#[arg(long)]
pub cache_dir: Option<PathBuf>,
#[arg(long, default_value = "raster")]
pub name: String,
#[arg(long)]
pub attribution: Option<String>,
}
#[derive(Debug, Parser)]
#[command(
name = "geolith reconstruct",
about = "drone video → 3D Tiles (ffmpeg → COLMAP → brush → splat-tiles)",
version
)]
pub struct ReconstructArgs {
#[arg(long)]
pub video: PathBuf,
#[arg(long, short)]
pub output: PathBuf,
#[arg(long, default_value = "2.0")]
pub fps: f64,
#[arg(long)]
pub max_frames: Option<usize>,
#[arg(long, default_value = "colmap")]
pub colmap_bin: String,
#[arg(long, default_value = "brush-cli")]
pub brush_bin: String,
#[arg(long, default_value = "30000")]
pub train_iters: u32,
#[arg(long, default_value = "0", allow_hyphen_values = true)]
pub longitude: f64,
#[arg(long, default_value = "0", allow_hyphen_values = true)]
pub latitude: f64,
#[arg(long, default_value = "0", allow_hyphen_values = true)]
pub altitude: f64,
#[arg(long, default_value = "0")]
pub crop_percentile: f64,
#[arg(long, default_value = "0")]
pub crop_radial_percentile: f64,
#[arg(long, default_value = "1")]
pub scale: f32,
#[arg(long, default_value = "0")]
pub coverage_boost_scale: f32,
#[arg(long, default_value = "100000")]
pub max_splats_per_tile: usize,
#[arg(long, default_value = "6")]
pub max_depth: u8,
#[arg(long, default_value = "64")]
pub root_geometric_error: f64,
#[arg(long, default_value = "true")]
pub emit_scene_spz: bool,
}
impl ReconstructArgs {
#[must_use]
pub fn options(&self) -> crate::reconstruct::ReconstructOptions {
crate::reconstruct::ReconstructOptions {
fps: self.fps,
max_frames: self.max_frames,
colmap_bin: self.colmap_bin.clone(),
brush_bin: self.brush_bin.clone(),
train_iters: self.train_iters,
longitude: self.longitude,
latitude: self.latitude,
altitude: self.altitude,
crop_percentile: self.crop_percentile,
crop_radial_percentile: self.crop_radial_percentile,
scale: self.scale,
coverage_boost_scale: self.coverage_boost_scale,
max_splats_per_tile: self.max_splats_per_tile,
max_depth: self.max_depth,
root_geometric_error: self.root_geometric_error,
emit_scene_spz: self.emit_scene_spz,
}
}
}
pub use crate::dataset::cli::{
AreasArgs, AreasDownloadArgs, BuildArgs, CheckDownloadArgs, DatasetAction, DatasetArgs,
DownloadsAction, DownloadsArgs, InspectArgs, KeysArgs, NormalsArgs, NumbersDownloadArgs,
StageArgs, StatusArgs, ValuesArgs, VerifyArgs,
};
#[derive(Debug, Parser)]
#[command(
name = "geolith notices",
about = "print the notices of third-party code and data",
version
)]
pub struct NoticesArgs {}
#[non_exhaustive]
#[derive(Debug)]
pub enum Command {
Terrain(Box<TerrainArgs>),
SplatTiles(Box<SplatTilesArgs>),
Raster(Box<RasterArgs>),
Reconstruct(Box<ReconstructArgs>),
Dataset(Box<DatasetArgs>),
Notices,
Tiles(Box<Config>),
}
#[must_use]
pub fn is_subcommand(argument: &str) -> bool {
matches!(
argument,
VERB_TERRAIN
| VERB_SPLAT_TILES
| VERB_RASTER
| VERB_RECONSTRUCT
| VERB_DATASET
| VERB_NOTICES
)
}
pub fn parse_from<I, T>(args: I) -> Result<Command, clap::Error>
where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
let argv: Vec<std::ffi::OsString> = args.into_iter().map(Into::into).collect();
let verb = argv
.get(1)
.and_then(|arg| arg.to_str())
.filter(|arg| is_subcommand(arg))
.map(str::to_owned);
match verb.as_deref() {
Some(VERB_TERRAIN) => {
let mut forwarded = vec![std::ffi::OsString::from("geolith terrain")];
forwarded.extend(argv.into_iter().skip(2));
TerrainArgs::try_parse_from(forwarded).map(|a| Command::Terrain(Box::new(a)))
}
Some(VERB_SPLAT_TILES) => {
let mut forwarded = vec![std::ffi::OsString::from("geolith splat-tiles")];
forwarded.extend(argv.into_iter().skip(2));
SplatTilesArgs::try_parse_from(forwarded).map(|a| Command::SplatTiles(Box::new(a)))
}
Some(VERB_RASTER) => {
let mut forwarded = vec![std::ffi::OsString::from("geolith raster")];
forwarded.extend(argv.into_iter().skip(2));
RasterArgs::try_parse_from(forwarded).map(|a| Command::Raster(Box::new(a)))
}
Some(VERB_RECONSTRUCT) => {
let mut forwarded = vec![std::ffi::OsString::from("geolith reconstruct")];
forwarded.extend(argv.into_iter().skip(2));
ReconstructArgs::try_parse_from(forwarded).map(|a| Command::Reconstruct(Box::new(a)))
}
Some(VERB_NOTICES) => {
let mut forwarded = vec![std::ffi::OsString::from("geolith notices")];
forwarded.extend(argv.into_iter().skip(2));
NoticesArgs::try_parse_from(forwarded).map(|_| Command::Notices)
}
Some(VERB_DATASET) => {
let mut forwarded = vec![std::ffi::OsString::from("geolith dataset")];
forwarded.extend(argv.into_iter().skip(2));
DatasetArgs::try_parse_from(forwarded).map(|a| Command::Dataset(Box::new(a)))
}
_ => Config::try_parse_from(argv)
.and_then(|c| c.check_required().map(|()| c))
.map(|c| Command::Tiles(Box::new(c))),
}
}
#[must_use]
pub fn parse_args() -> Command {
match parse_from(std::env::args_os()) {
Ok(command) => command,
Err(error) => error.exit(),
}
}
impl TerrainArgs {
pub fn tiler_options(&self) -> geolith::error::Result<crate::terrain::TerrainTilerOptions> {
let clip = match &self.clip {
Some(path) => Some(std::sync::Arc::new(crate::terrain::ClipMask::from_geojson(
path,
)?)),
None => None,
};
Ok(crate::terrain::TerrainTilerOptions {
min_zoom: self.min_zoom,
max_zoom: self.max_zoom,
tile_size: self.tile_size,
encoding: TerrainEncoding::parse(&self.encoding)?,
clip,
})
}
}
impl RasterArgs {
pub fn build_options(&self) -> geolith::error::Result<crate::raster::RasterBuildOptions> {
let template = crate::raster::UrlTemplate::parse(&self.url_template)?;
let bbox = match &self.bbox {
Some(raw) => {
let parsed = crate::source::bbox_filter::Bbox::parse(raw)?;
Some((
parsed.min_lon,
parsed.min_lat,
parsed.max_lon,
parsed.max_lat,
))
}
None => None,
};
let tile_type = match self.format.as_str() {
"jpeg" | "jpg" => geolith::output::writer::TileType::Jpeg,
"png" => geolith::output::writer::TileType::Png,
"webp" => geolith::output::writer::TileType::Webp,
other => {
return Err(geolith::error::GeolithError::RasterSource(format!(
"unknown raster format {other:?} — expected jpeg, png, or webp"
)));
}
};
Ok(crate::raster::RasterBuildOptions {
template,
pyramid: crate::raster::PyramidSpec {
min_zoom: self.min_zoom,
max_zoom: self.max_zoom,
bbox,
bbox_min_zoom: self.bbox_min_zoom,
},
tile_type,
concurrency: self.concurrency,
request_delay: std::time::Duration::from_millis(self.request_delay_ms),
attempts: self.attempts,
cache_dir: self
.cache_dir
.clone()
.unwrap_or_else(|| std::env::temp_dir().join("geolith-raster")),
name: self.name.clone(),
attribution: self.attribution.clone(),
})
}
}
impl SplatTilesArgs {
#[must_use]
pub fn job(&self) -> crate::splat::SplatJob {
crate::splat::SplatJob {
ply: self.ply.clone(),
output: self.output.clone(),
crop_percentile: self.crop_percentile,
scale: self.scale,
coverage_boost_scale: self.coverage_boost_scale,
emit_scene_spz: self.emit_scene_spz,
options: self.tileset_options(),
}
}
#[must_use]
pub const fn tileset_options(&self) -> crate::splat::SplatTilesetOptions {
crate::splat::SplatTilesetOptions {
longitude: self.longitude,
latitude: self.latitude,
altitude: self.altitude,
max_splats_per_tile: self.max_splats_per_tile,
max_depth: self.max_depth,
root_geometric_error: self.root_geometric_error,
antialiased: self.antialiased,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn tiles_argv() -> Vec<&'static str> {
vec![
"geolith",
"--data",
"/tmp/data",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
]
}
fn dataset_verbs() -> Vec<(String, Vec<String>)> {
use clap::CommandFactory;
fn walk(cmd: &clap::Command, prefix: &str, out: &mut Vec<(String, Vec<String>)>) {
for sub in cmd.get_subcommands() {
let name = format!("{prefix}{}", sub.get_name());
let flags = sub
.get_arguments()
.filter_map(clap::Arg::get_long)
.filter(|l| !matches!(*l, "help" | "version"))
.map(|l| format!("--{l}"))
.collect();
out.push((name.clone(), flags));
walk(sub, &format!("{name} "), out);
}
}
let mut out = Vec::new();
walk(&DatasetArgs::command(), "dataset ", &mut out);
out
}
#[test]
fn every_dataset_verb_and_flag_is_documented() {
let readme = include_str!("../../README.md");
let agents = include_str!("../../AGENTS.md");
let verbs = dataset_verbs();
assert!(
verbs.iter().any(|(v, _)| v == "dataset values"),
"{verbs:?}"
);
let mut missing = Vec::new();
for (verb, flags) in &verbs {
if verb == "dataset downloads" {
continue;
}
let last = verb.rsplit(' ').next().unwrap_or_default();
if !readme.contains(&format!("geolith {verb}")) {
missing.push(format!("README: geolith {verb}"));
}
if !agents.contains(&format!("geolith {verb}")) && !agents.contains(&format!("|{last}"))
{
missing.push(format!("AGENTS.md: {verb}"));
}
for flag in flags {
if !readme.contains(flag.as_str()) {
missing.push(format!("README: {verb} {flag}"));
}
}
}
for flag in ["dataset normals --cache", "dataset values --config"] {
if !agents.contains(flag) {
missing.push(format!("AGENTS.md: {flag}"));
}
}
assert!(missing.is_empty(), "undocumented: {missing:?}");
}
#[test]
fn verbs_are_recognised() {
assert!(is_subcommand("terrain"));
assert!(is_subcommand("splat-tiles"));
assert!(is_subcommand("raster"));
assert!(!is_subcommand("--data"));
assert!(!is_subcommand("tiles"));
}
#[test]
fn flat_invocation_still_reaches_the_tile_pipeline() {
let command = parse_from(tiles_argv()).expect("flat flags parse");
match command {
Command::Tiles(config) => {
assert_eq!(config.output_format, "tiles");
assert_eq!(config.data, Some(PathBuf::from("/tmp/data")));
}
other => panic!("expected the tile pipeline, got {other:?}"),
}
}
#[test]
fn terrain_subcommand_parses_required_flags() {
let command = parse_from([
"geolith",
"terrain",
"--dem",
"/tmp/dsm.tif",
"--output",
"/tmp/terrain.pmtiles",
])
.expect("terrain parses");
match command {
Command::Terrain(args) => {
assert_eq!(args.dem, [PathBuf::from("/tmp/dsm.tif")]);
assert_eq!(args.output, PathBuf::from("/tmp/terrain.pmtiles"));
assert_eq!(args.encoding, "mapbox");
assert_eq!(args.min_zoom, 0);
assert_eq!(args.max_zoom, 14);
assert_eq!(args.tile_size, 512);
assert_eq!(args.name, "terrain");
assert!(args.dem_crs.is_none());
}
other => panic!("expected terrain, got {other:?}"),
}
}
#[test]
fn terrain_subcommand_accepts_overrides() {
let command = parse_from([
"geolith",
"terrain",
"--dem",
"/tmp/dsm.tif",
"--output",
"/tmp/t.pmtiles",
"--encoding",
"terrarium",
"--min-zoom",
"8",
"--max-zoom",
"16",
"--tile-size",
"256",
"--dem-crs",
"32632",
"--name",
"belvedere",
])
.expect("terrain parses");
match command {
Command::Terrain(args) => {
assert_eq!(args.encoding, "terrarium");
assert_eq!(args.min_zoom, 8);
assert_eq!(args.max_zoom, 16);
assert_eq!(args.tile_size, 256);
assert_eq!(args.dem_crs, Some(32_632));
assert_eq!(args.name, "belvedere");
let options = args.tiler_options().expect("known encoding");
assert_eq!(options.encoding, TerrainEncoding::Terrarium);
assert_eq!(options.tile_size, 256);
}
other => panic!("expected terrain, got {other:?}"),
}
}
#[test]
fn terrain_rejects_unknown_encoding_when_resolving_options() {
let command = parse_from([
"geolith",
"terrain",
"--dem",
"/tmp/dsm.tif",
"--output",
"/tmp/t.pmtiles",
"--encoding",
"rainbow",
])
.expect("flag parses; validation happens on resolve");
match command {
Command::Terrain(args) => assert!(args.tiler_options().is_err()),
other => panic!("expected terrain, got {other:?}"),
}
}
#[test]
fn terrain_requires_dem_and_output() {
assert!(parse_from(["geolith", "terrain"]).is_err());
assert!(parse_from(["geolith", "terrain", "--dem", "/tmp/d.tif"]).is_err());
}
#[test]
fn splat_subcommand_parses_required_flags() {
let command = parse_from([
"geolith",
"splat-tiles",
"--ply",
"/tmp/scene.ply",
"--output",
"/tmp/tileset",
"--longitude",
"7.9797",
"--latitude",
"45.9756",
])
.expect("splat-tiles parses");
match command {
Command::SplatTiles(args) => {
assert_eq!(args.ply, PathBuf::from("/tmp/scene.ply"));
assert!((args.longitude - 7.9797).abs() < 1e-9);
assert!((args.latitude - 45.9756).abs() < 1e-9);
assert!((args.altitude - 0.0).abs() < 1e-9);
assert_eq!(args.max_splats_per_tile, 100_000);
assert_eq!(args.max_depth, 6);
assert!(args.emit_scene_spz);
assert!(!args.antialiased);
}
other => panic!("expected splat-tiles, got {other:?}"),
}
}
#[test]
fn splat_subcommand_accepts_negative_coordinates() {
let command = parse_from([
"geolith",
"splat-tiles",
"--ply",
"/tmp/scene.ply",
"--output",
"/tmp/tileset",
"--longitude",
"-122.4194",
"--latitude",
"-37.7749",
"--altitude",
"-50",
])
.expect("negative coordinates parse");
match command {
Command::SplatTiles(args) => {
assert!(args.longitude < 0.0, "southern/western anchors are valid");
assert!(args.latitude < 0.0);
assert!(args.altitude < 0.0);
}
other => panic!("expected splat-tiles, got {other:?}"),
}
}
#[test]
fn splat_options_carry_through_to_the_tileset_builder() {
let command = parse_from([
"geolith",
"splat-tiles",
"--ply",
"/tmp/scene.ply",
"--output",
"/tmp/tileset",
"--longitude",
"7.9797",
"--latitude",
"45.9756",
"--altitude",
"2250",
"--max-splats-per-tile",
"50000",
"--max-depth",
"4",
"--root-geometric-error",
"128",
"--antialiased",
])
.expect("splat-tiles parses");
match command {
Command::SplatTiles(args) => {
let options = args.tileset_options();
assert!((options.altitude - 2250.0).abs() < 1e-9);
assert_eq!(options.max_splats_per_tile, 50_000);
assert_eq!(options.max_depth, 4);
assert!((options.root_geometric_error - 128.0).abs() < 1e-9);
assert!(options.antialiased);
}
other => panic!("expected splat-tiles, got {other:?}"),
}
}
#[test]
fn splat_requires_an_anchor() {
assert!(
parse_from([
"geolith",
"splat-tiles",
"--ply",
"/tmp/s.ply",
"--output",
"/tmp/out",
])
.is_err(),
"a tileset without a geographic anchor cannot be placed on the globe"
);
}
#[test]
fn raster_subcommand_parses_required_flags() {
let command = parse_from([
"geolith",
"raster",
"--url-template",
"https://t.example/{z}/{x}/{y}.jpg",
"--output",
"/tmp/planet.pmtiles",
])
.expect("raster parses");
match command {
Command::Raster(args) => {
assert_eq!(args.output, PathBuf::from("/tmp/planet.pmtiles"));
assert_eq!(args.min_zoom, 0);
assert_eq!(args.max_zoom, 8);
assert_eq!(args.format, "jpeg");
assert_eq!(args.concurrency, 8);
assert_eq!(args.request_delay_ms, 50);
assert_eq!(args.attempts, 5);
assert!(args.bbox.is_none());
assert!(args.cache_dir.is_none());
}
other => panic!("expected raster, got {other:?}"),
}
}
#[test]
fn raster_build_options_resolve_the_hybrid_pyramid() {
let command = parse_from([
"geolith",
"raster",
"--url-template",
"https://t.example/{z}/{x}/{y}.jpg",
"--output",
"/tmp/planet.pmtiles",
"--min-zoom",
"0",
"--max-zoom",
"12",
"--bbox",
"68.0,6.5,97.5,37.2",
"--bbox-min-zoom",
"9",
"--format",
"png",
"--cache-dir",
"/tmp/rcache",
"--attribution",
"Sentinel-2 cloudless by EOX",
])
.expect("raster parses");
match command {
Command::Raster(args) => {
let options = args.build_options().expect("valid options");
assert_eq!(options.pyramid.min_zoom, 0);
assert_eq!(options.pyramid.max_zoom, 12);
assert_eq!(options.pyramid.bbox_min_zoom, 9);
let bbox = options.pyramid.bbox.expect("bbox parsed");
assert!((bbox.0 - 68.0).abs() < 1e-9);
assert!((bbox.3 - 37.2).abs() < 1e-9);
assert_eq!(options.tile_type, geolith::output::writer::TileType::Png);
assert_eq!(options.cache_dir, PathBuf::from("/tmp/rcache"));
assert_eq!(
options.attribution.as_deref(),
Some("Sentinel-2 cloudless by EOX")
);
}
other => panic!("expected raster, got {other:?}"),
}
}
#[test]
fn raster_build_options_reject_bad_inputs() {
let bad_template = parse_from([
"geolith",
"raster",
"--url-template",
"https://t.example/{z}/{x}.jpg",
"--output",
"/tmp/p.pmtiles",
])
.expect("parses; validation happens on resolve");
match bad_template {
Command::Raster(args) => assert!(args.build_options().is_err()),
other => panic!("expected raster, got {other:?}"),
}
let bad_format = parse_from([
"geolith",
"raster",
"--url-template",
"https://t.example/{z}/{x}/{y}.jpg",
"--output",
"/tmp/p.pmtiles",
"--format",
"tiff",
])
.expect("parses; validation happens on resolve");
match bad_format {
Command::Raster(args) => {
let err = args.build_options().expect_err("tiff is not a tile format");
assert!(format!("{err}").contains("tiff"));
}
other => panic!("expected raster, got {other:?}"),
}
}
#[test]
fn raster_requires_template_and_output() {
assert!(parse_from(["geolith", "raster"]).is_err());
assert!(
parse_from([
"geolith",
"raster",
"--url-template",
"https://t.example/{z}/{x}/{y}.jpg",
])
.is_err()
);
}
#[test]
fn subcommand_help_renders_for_each_verb() {
for verb in [VERB_TERRAIN, VERB_SPLAT_TILES, VERB_RASTER] {
let error = parse_from(["geolith", verb, "--help"]).expect_err("help exits via error");
assert_eq!(
error.kind(),
clap::error::ErrorKind::DisplayHelp,
"{verb} --help must render its own usage"
);
}
}
#[test]
fn unknown_verb_falls_through_to_the_tile_parser() {
let error = parse_from(["geolith", "wobble"]).expect_err("not a tile invocation");
assert_ne!(
error.kind(),
clap::error::ErrorKind::DisplayHelp,
"an unknown verb is a tile-parser error, not a subcommand"
);
}
#[test]
fn bare_invocation_is_a_tile_parser_error() {
let error = parse_from(["geolith"]).expect_err("the tile pipeline needs flags");
assert_ne!(error.kind(), clap::error::ErrorKind::DisplayHelp);
}
#[test]
fn subcommand_version_renders_for_each_verb() {
for verb in [VERB_TERRAIN, VERB_SPLAT_TILES, VERB_RASTER] {
let error =
parse_from(["geolith", verb, "--version"]).expect_err("version exits via error");
assert_eq!(
error.kind(),
clap::error::ErrorKind::DisplayVersion,
"{verb} --version must render its own version"
);
}
}
#[test]
fn a_verb_after_the_first_argument_is_not_a_subcommand() {
let mut argv = tiles_argv();
argv.push("terrain");
let error = parse_from(argv).expect_err("'terrain' in tail position is not a verb");
assert_ne!(
error.kind(),
clap::error::ErrorKind::DisplayHelp,
"only argv[1] selects a subcommand"
);
}
#[test]
fn terrain_rejects_a_non_numeric_zoom() {
assert!(
parse_from([
"geolith",
"terrain",
"--dem",
"/tmp/d.tif",
"--output",
"/tmp/t.pmtiles",
"--max-zoom",
"high",
])
.is_err(),
"zoom levels are numeric"
);
}
#[test]
fn splat_rejects_a_non_numeric_anchor() {
assert!(
parse_from([
"geolith",
"splat-tiles",
"--ply",
"/tmp/s.ply",
"--output",
"/tmp/out",
"--longitude",
"west",
"--latitude",
"45.0",
])
.is_err(),
"the anchor is numeric"
);
}
#[test]
fn dataset_is_a_verb() {
assert!(is_subcommand("dataset"));
}
#[test]
fn dataset_areas_parses_its_flags() {
let command = parse_from([
"geolith",
"dataset",
"areas",
"--overture",
"/o",
"--countries",
"IN",
"--india-outline",
"/i.geojson",
"--out",
"/d",
])
.expect("dataset areas parses");
match command {
Command::Dataset(args) => match args.action {
DatasetAction::Areas(x) => {
assert_eq!(x.countries.as_deref(), Some("IN"));
assert_eq!(x.subtype, "county");
assert_eq!(x.max_zoom, 8);
assert_eq!(x.india_outline, Some(PathBuf::from("/i.geojson")));
assert_eq!(x.overture, Some(PathBuf::from("/o")));
assert_eq!(x.out, PathBuf::from("/d"));
assert!(x.release.is_none());
}
other => panic!("expected dataset areas, got {other:?}"),
},
other => panic!("expected dataset, got {other:?}"),
}
}
#[test]
fn dataset_build_needs_out() {
assert!(
parse_from([
"geolith",
"dataset",
"build",
"--config",
"/c.json",
"--rasters",
"/r",
"--areas",
"/a.geojson",
])
.is_err(),
"a build without --out has nowhere to write"
);
}
#[test]
fn dataset_normals_defaults_the_baseline() {
let command = parse_from([
"geolith",
"dataset",
"normals",
"--config",
"/c.json",
"--rasters",
"/r",
"--areas",
"/a.geojson",
"--slots",
"06-1,06-2",
"--out",
"/n.csv",
])
.expect("dataset normals parses");
match command {
Command::Dataset(args) => match args.action {
DatasetAction::Normals(x) => {
assert_eq!(x.baseline, "1991-2020");
assert_eq!(x.slots, "06-1,06-2");
assert_eq!(x.out, PathBuf::from("/n.csv"));
assert_eq!(x.cache, None);
}
other => panic!("expected dataset normals, got {other:?}"),
},
other => panic!("expected dataset, got {other:?}"),
}
}
#[test]
fn terrain_resolves_the_mapbox_encoding_by_default() {
let command = parse_from([
"geolith",
"terrain",
"--dem",
"/tmp/dsm.tif",
"--output",
"/tmp/t.pmtiles",
])
.expect("terrain parses");
match command {
Command::Terrain(args) => {
let options = args.tiler_options().expect("default encoding is valid");
assert_eq!(options.encoding, TerrainEncoding::Mapbox);
assert_eq!(options.min_zoom, 0);
assert_eq!(options.max_zoom, 14);
assert_eq!(options.tile_size, 512);
}
other => panic!("expected terrain, got {other:?}"),
}
}
}