geolith_cli/config.rs
1//! CLI configuration via clap.
2
3// The clap help text is golden-tested and names placeholders such as <output>.
4#![allow(rustdoc::invalid_html_tags)]
5
6use clap::{CommandFactory, Parser};
7use geolith_tiles_builder::TilesConfig;
8use std::path::{Path, PathBuf};
9
10/// A path flag that only some output formats read.
11#[non_exhaustive]
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum PathFlag {
14 /// `--data`.
15 Data,
16 /// `--natural-earth`.
17 NaturalEarth,
18 /// `--water-polygons`.
19 WaterPolygons,
20 /// `--land-polygons`.
21 LandPolygons,
22 /// `--output`.
23 Output,
24}
25
26impl PathFlag {
27 /// The flag as the usage line names it.
28 #[must_use]
29 pub const fn usage(self) -> &'static str {
30 match self {
31 Self::Data => "--data <DATA>",
32 Self::NaturalEarth => "--natural-earth <NATURAL_EARTH>",
33 Self::WaterPolygons => "--water-polygons <WATER_POLYGONS>",
34 Self::LandPolygons => "--land-polygons <LAND_POLYGONS>",
35 Self::Output => "--output <OUTPUT>",
36 }
37 }
38}
39
40pub use geolith_search_builder::PgIndexFlavor;
41
42/// Switches that reuse work an earlier run already did, flattened into
43/// [`Config`] so the flags stay `--node-cache` and `--resume`.
44#[derive(Debug, Parser)]
45pub struct RunReuse {
46 /// Enable node store caching between runs.
47 ///
48 /// When enabled (default), a sidecar `.meta.json` file is written
49 /// alongside the node store. On re-runs with the same PBF file,
50 /// the node collection pass is skipped entirely — reducing from
51 /// 2 PBF reads to 1.
52 #[arg(long, default_value = "true")]
53 pub node_cache: bool,
54
55 /// Resume from existing sort chunks in --tmpdir, skipping Phase 1.
56 ///
57 /// When set, the pipeline discovers chunk files from the temporary
58 /// directory and proceeds directly to merge + encode + write.
59 /// Requires --tmpdir to point at a directory with sort chunks from
60 /// a previous (interrupted) run.
61 #[arg(long, default_value = "false")]
62 pub resume: bool,
63}
64
65/// Rust vector tile generator — OSM + Overture Maps → protomaps `PMTiles`.
66#[derive(Debug, Parser)]
67#[command(
68 name = "geolith",
69 version,
70 long_version = crate::cli::LONG_VERSION,
71 about,
72 override_usage = "geolith --data <DATA> --natural-earth <NATURAL_EARTH> --water-polygons <WATER_POLYGONS> --land-polygons <LAND_POLYGONS> --output <OUTPUT>\n geolith --output-format routing --osm-pbf <OSM_PBF> --routing-output <ROUTING_OUTPUT>"
73)]
74pub struct Config {
75 /// Path to Overture Maps data directory (hive-partitioned Parquet).
76 ///
77 /// Required by the tiles and geocoding formats.
78 #[arg(long)]
79 pub data: Option<PathBuf>,
80
81 /// Path to planet.osm.pbf file (optional — omit for Overture-only builds).
82 #[arg(long)]
83 pub osm_pbf: Option<PathBuf>,
84
85 /// Path to Natural Earth SQLite file.
86 ///
87 /// Required by the tiles format.
88 #[arg(long)]
89 pub natural_earth: Option<PathBuf>,
90
91 /// Path to water-polygons-split-3857 shapefile directory.
92 ///
93 /// Required by the tiles format.
94 #[arg(long)]
95 pub water_polygons: Option<PathBuf>,
96
97 /// Path to land-polygons-split-3857 shapefile directory.
98 ///
99 /// Required by the tiles format.
100 #[arg(long)]
101 pub land_polygons: Option<PathBuf>,
102
103 /// Path to India boundary `GeoJSON` file (optional).
104 #[arg(long)]
105 pub india_boundary: Option<PathBuf>,
106
107 /// India's outline on the Survey of India map (`GeoJSON` polygons, e.g.
108 /// `DataMeet`'s `india-composite.geojson`). Geocoding draws and resolves
109 /// India, Ladakh, Jammu and Kashmir, Pakistan and China with it;
110 /// required when the geocoding build covers India, and when the
111 /// --routing-admins source holds India (routing nodes inside it are in
112 /// India).
113 #[arg(long)]
114 pub india_outline: Option<PathBuf>,
115
116 /// Output `PMTiles` file path.
117 ///
118 /// Required by the tiles format, and by geocoding without
119 /// --geocoding-output.
120 #[arg(long, short)]
121 pub output: Option<PathBuf>,
122
123 /// Bounding box filter: `min_lon,min_lat,max_lon,max_lat`
124 #[arg(long, allow_hyphen_values = true)]
125 pub bbox: Option<String>,
126
127 /// Maximum zoom level (default: 15).
128 #[arg(long, default_value = "15")]
129 pub max_zoom: u8,
130
131 /// Number of threads (default: available parallelism).
132 #[arg(long)]
133 pub threads: Option<usize>,
134
135 /// Sort buffer size per thread in megabytes (0 = auto-detect).
136 ///
137 /// When set to 0 (the default), the chunk size is computed as
138 /// `min(2 GB, total_RAM / (3 × threads))`. Larger chunks produce
139 /// fewer files, speeding up the k-way merge phase.
140 #[arg(long, default_value = "0")]
141 pub chunk_size_mb: usize,
142
143 /// Temporary directory for sort chunks.
144 #[arg(long)]
145 pub tmpdir: Option<PathBuf>,
146
147 /// Path to node coordinate store (mmap file for OSM processing).
148 #[arg(long)]
149 pub node_store: Option<PathBuf>,
150
151 /// Buildings data source: "osm", "overture", or "both".
152 #[arg(long, default_value = "both")]
153 pub buildings_source: String,
154
155 /// Places data source: "osm", "overture", or "both".
156 #[arg(long, default_value = "both")]
157 pub places_source: String,
158
159 /// Divisions data source: "overture" or "none".
160 #[arg(long, default_value = "overture")]
161 pub divisions_source: String,
162
163 /// Landcover data source: "overture" or "none".
164 #[arg(long, default_value = "overture")]
165 pub landcover_source: String,
166
167 /// Bathymetry data source: "overture" or "none".
168 #[arg(long, default_value = "overture")]
169 pub bathymetry_source: String,
170
171 /// Roads data source: "osm", "overture", or "both".
172 #[arg(long, default_value = "both")]
173 pub roads_source: String,
174
175 /// POIs data source: "osm", "overture", or "both".
176 #[arg(long, default_value = "both")]
177 pub pois_source: String,
178
179 /// Water data source: "osm", "overture", or "both".
180 #[arg(long, default_value = "both")]
181 pub water_source: String,
182
183 /// Landuse data source: "osm", "overture", or "both".
184 #[arg(long, default_value = "both")]
185 pub landuse_source: String,
186
187 /// Enable node store caching between runs.
188 ///
189 /// When enabled (default), a sidecar `.meta.json` file is written
190 /// alongside the node store. On re-runs with the same PBF file,
191 /// the node collection pass is skipped entirely — reducing from
192 /// 2 PBF reads to 1.
193 #[command(flatten)]
194 pub reuse: RunReuse,
195
196 /// Output format: "tiles" (default), "geocoding" or "routing".
197 ///
198 /// "routing" builds the routing graph from --osm-pbf and writes a
199 /// `.glx` file with one routing part to --routing-output. Any other
200 /// value fails with an error.
201 #[arg(long, default_value = "tiles")]
202 pub output_format: String,
203
204 /// Tile encoding format: "mlt" (default) or "mvt".
205 ///
206 /// MLT (`MapLibre` Tiles) uses columnar encoding with built-in compression,
207 /// producing 50–80% smaller tiles. MVT uses protobuf + gzip.
208 #[arg(long, default_value = "mvt")]
209 pub tile_format: String,
210
211 /// Directory containing GERS bridge Parquet files for OSM deduplication.
212 ///
213 /// When provided, all `.parquet` files in this directory (recursively) are
214 /// loaded into the deduplication index. If not set, geolith automatically
215 /// looks for a `gers-bridge/` sibling directory next to `--data`.
216 ///
217 /// Expected structure:
218 /// ```text
219 /// gers-bridge/
220 /// ├── buildings/*.zstd.parquet
221 /// ├── transportation/*.zstd.parquet
222 /// └── divisions/*.zstd.parquet
223 /// ```
224 #[arg(long)]
225 pub bridge_dir: Option<PathBuf>,
226
227 /// Disable GERS conflation even when bridge files are found.
228 ///
229 /// By default, conflation is enabled automatically when bridge files
230 /// are discovered. Set this flag to skip deduplication.
231 #[arg(long, default_value = "false")]
232 pub no_conflate: bool,
233
234 /// Paths to individual GERS bridge Parquet files (can be specified multiple times).
235 ///
236 /// Alternative to `--bridge-dir` for specifying individual bridge files.
237 /// These are loaded in addition to any files found via `--bridge-dir`.
238 #[arg(long)]
239 pub bridge_files: Vec<PathBuf>,
240
241 /// Geocoding output format: "glx" (default: one `.glx` index file that
242 /// geolith search serves), "pg-copy" (rows and schema for your own
243 /// Postgres), "photon", or "pelias".
244 ///
245 /// Only used when --output-format geocoding.
246 #[arg(long, default_value = "glx")]
247 pub geocoding_format: String,
248
249 /// Text index emitted in the companion DDL for the pg-copy format.
250 ///
251 /// `tin` (default) needs the `tin` extension, available on `PlanetScale`
252 /// Postgres and Neki. `gin` needs no extension and runs anywhere.
253 #[arg(long, value_enum, default_value_t = PgIndexFlavor::Tin)]
254 pub pg_index_flavor: PgIndexFlavor,
255
256 /// Output path for geocoding data.
257 ///
258 /// Only used when --output-format geocoding. Defaults to <output>.tsv for
259 /// pg-copy, <output>.ndjson for photon and pelias, and <output>.glx for glx.
260 #[arg(long)]
261 pub geocoding_output: Option<PathBuf>,
262
263 /// Nominatim's Wikipedia importance file, `wikimedia-importance.csv.gz`
264 /// from <https://nominatim.org/data/>. An OSM place with a `wikidata`
265 /// tag takes the importance of its Wikipedia article, so "London" finds
266 /// the city before a shop named after it. Without the file, a place
267 /// takes a default from its type.
268 ///
269 /// Only used when --output-format geocoding.
270 #[arg(long)]
271 pub wikimedia_importance: Option<PathBuf>,
272
273 /// Output path for the routing `.glx` file.
274 ///
275 /// Only used when --output-format routing.
276 #[arg(long)]
277 pub routing_output: Option<PathBuf>,
278
279 /// Directory to write the auto metric to as a turn-expanded graph
280 /// (`RoutingKit` vectors: `first_out`, `head`, `travel_time`, `latitude`,
281 /// `longitude` and the `vertex_*` mapping), the input of the
282 /// customizable contraction hierarchy.
283 ///
284 /// Only used when --output-format routing.
285 #[arg(long)]
286 pub routing_metric_out: Option<PathBuf>,
287
288 /// Costing profiles to build a customizable contraction hierarchy for,
289 /// comma-separated (`auto`, `pedestrian`, `bicycle`). Each becomes its
290 /// own set of sections in the routing part (glx spec v1, 10.5).
291 ///
292 /// Only used when --output-format routing.
293 #[arg(long, value_delimiter = ',')]
294 pub routing_cch: Vec<String>,
295
296 /// Directory of historical speeds in the reference CSV format: one file
297 /// per graph tile named by tile path (`2/000/753/554.csv`), rows
298 /// `edge_graph_id,free_flow_kph,constrained_kph,encoded_dct`. Fills the
299 /// tiles' predicted-speeds section and flow speeds exactly as
300 /// `valhalla_add_predicted_traffic` does.
301 ///
302 /// Only used when --output-format routing.
303 #[arg(long)]
304 pub routing_predicted_speeds: Option<PathBuf>,
305
306 /// Default speed table in the reference `default_speeds_config` format
307 /// (`OpenStreetMapSpeeds` `default_speeds.json`): km/h per region,
308 /// rural/suburban/urban density band, road class, link, roundabout and
309 /// service use. A configured speed replaces the heuristic speed of every
310 /// vehicular non-ferry edge, a tagged `maxspeed` included, exactly as
311 /// the reference `SpeedAssigner` does.
312 ///
313 /// Only used when --output-format routing.
314 #[arg(long)]
315 pub routing_default_speeds: Option<PathBuf>,
316
317 /// OSM PBF whose admin boundary relations give each routing node its
318 /// country and state, side of the road and country access rules, and
319 /// each edge its row of --routing-default-speeds: the reference's admin
320 /// database (`valhalla_build_admins`), read from relations with
321 /// `type=boundary` at `admin_level` 2 and 4 (3 and 6 in a few countries)
322 /// and their member ways and nodes. May be the --osm-pbf itself or a
323 /// file of boundaries only. Nodes inside India take India as drawn by
324 /// the Survey of India: --india-outline is required when the source
325 /// holds India.
326 ///
327 /// Only used when --output-format routing.
328 #[arg(long)]
329 pub routing_admins: Option<PathBuf>,
330
331 /// Time zone areas for the routing nodes: the `.shp` of a
332 /// timezone-boundary-builder shapefile release
333 /// (`combined-shapefile-with-oceans-1970.shp`, attribute `tzid`), as
334 /// the reference's `valhalla_build_timezones` imports it. Each node
335 /// takes the index of the zone that holds it, which the router uses for
336 /// local time. Without it every node has no time zone and routes at a
337 /// `date_time` run in UTC.
338 ///
339 /// Only used when --output-format routing.
340 #[arg(long)]
341 pub routing_timezones: Option<PathBuf>,
342
343 /// Delete each Overture Parquet file once its features are safely in the
344 /// sort chunks.
345 ///
346 /// Phase 1 streams every source exactly once and Phases 2-4 read only the
347 /// chunks, so the source tree can be released progressively rather than
348 /// held alongside it. That keeps the peak footprint near the release size
349 /// instead of `release + chunks`, which is the difference between fitting
350 /// on a disk-constrained machine and hitting ENOSPC mid-read.
351 ///
352 /// Only Overture inputs are affected, and only after both the read and the
353 /// chunk flush for a file succeed. Re-download the release to restore.
354 #[arg(long, default_value = "false")]
355 pub reclaim_source_after_read: bool,
356}
357
358impl Config {
359 /// Parse CLI arguments, exiting with a usage error when a flag the
360 /// output format reads is missing.
361 pub fn parse_args() -> Self {
362 let config = Self::parse();
363 if let Err(e) = config.check_required() {
364 e.exit();
365 }
366 config
367 }
368
369 /// The value of a path flag.
370 #[must_use]
371 pub fn path(&self, flag: PathFlag) -> Option<&Path> {
372 match flag {
373 PathFlag::Data => self.data.as_deref(),
374 PathFlag::NaturalEarth => self.natural_earth.as_deref(),
375 PathFlag::WaterPolygons => self.water_polygons.as_deref(),
376 PathFlag::LandPolygons => self.land_polygons.as_deref(),
377 PathFlag::Output => self.output.as_deref(),
378 }
379 }
380
381 /// The path flags the output format reads, in usage order: all five
382 /// for tiles (and an unknown format, which fails later), `--data` and
383 /// `--output` for geocoding (`--output` only without
384 /// `--geocoding-output`), none for routing.
385 #[must_use]
386 pub fn required_flags(&self) -> Vec<PathFlag> {
387 match self.output_format.as_str() {
388 "routing" => Vec::new(),
389 "geocoding" => {
390 let mut flags = vec![PathFlag::Data];
391 if self.geocoding_output.is_none() {
392 flags.push(PathFlag::Output);
393 }
394 flags
395 }
396 _ => vec![
397 PathFlag::Data,
398 PathFlag::NaturalEarth,
399 PathFlag::WaterPolygons,
400 PathFlag::LandPolygons,
401 PathFlag::Output,
402 ],
403 }
404 }
405
406 /// A usage error naming the flags in `missing`, worded as the
407 /// argument parser words a missing required argument.
408 fn missing_error(missing: &[PathFlag]) -> clap::Error {
409 let mut msg = String::from("the following required arguments were not provided:");
410 for f in missing {
411 msg.push_str("\n ");
412 msg.push_str(f.usage());
413 }
414 Self::command().error(clap::error::ErrorKind::MissingRequiredArgument, msg)
415 }
416
417 /// Check that every path flag the output format reads is present.
418 ///
419 /// # Errors
420 ///
421 /// A usage error naming each missing flag.
422 pub fn check_required(&self) -> Result<(), clap::Error> {
423 let missing: Vec<PathFlag> = self
424 .required_flags()
425 .into_iter()
426 .filter(|&f| self.path(f).is_none())
427 .collect();
428 if missing.is_empty() {
429 Ok(())
430 } else {
431 Err(Self::missing_error(&missing))
432 }
433 }
434
435 /// The value of a path flag the running format needs.
436 ///
437 /// # Errors
438 ///
439 /// The usage error for a missing required flag.
440 pub fn required_path(&self, flag: PathFlag) -> Result<&Path, clap::Error> {
441 self.path(flag).ok_or_else(|| Self::missing_error(&[flag]))
442 }
443
444 /// Check if India boundary fix is enabled.
445 pub const fn has_india_boundary(&self) -> bool {
446 self.india_boundary.is_some()
447 }
448
449 /// Check if a source should include OSM data.
450 pub fn uses_osm(&self, source: &str) -> bool {
451 self.tiles_view().uses_osm(source)
452 }
453
454 /// Check if a source should include Overture data.
455 pub fn uses_overture(&self, source: &str) -> bool {
456 self.tiles_view().uses_overture(source)
457 }
458
459 /// Whether Overture data should be included for a given layer.
460 ///
461 /// Layers without a dedicated source flag always include Overture data.
462 pub fn overture_enabled(&self, layer: crate::layers::Layer) -> bool {
463 self.tiles_view().overture_enabled(layer)
464 }
465
466 /// Whether OSM data should be included for a given layer.
467 ///
468 /// Returns `false` for all layers when `--osm-pbf` is not provided.
469 pub fn osm_enabled(&self, layer: crate::layers::Layer) -> bool {
470 self.tiles_view().osm_enabled(layer)
471 }
472
473 /// Compute the effective sort-buffer size in bytes per thread.
474 pub fn effective_chunk_bytes(&self) -> usize {
475 self.tiles_view().effective_chunk_bytes()
476 }
477
478 /// Discover all GERS bridge Parquet files for OSM deduplication.
479 ///
480 /// Resolution order: explicit `--bridge-files`, then `--bridge-dir`,
481 /// then the `gers-bridge/` sibling of `--data`.
482 #[must_use]
483 pub fn discover_bridge_files(&self) -> Vec<PathBuf> {
484 self.tiles_view().discover_bridge_files()
485 }
486
487 /// The tile build this invocation describes.
488 ///
489 /// # Errors
490 ///
491 /// A usage error naming each path flag the tile build needs and lacks.
492 pub fn tiles(&self) -> Result<TilesConfig, clap::Error> {
493 let missing: Vec<PathFlag> = [
494 PathFlag::Data,
495 PathFlag::NaturalEarth,
496 PathFlag::WaterPolygons,
497 PathFlag::LandPolygons,
498 PathFlag::Output,
499 ]
500 .into_iter()
501 .filter(|&f| self.path(f).is_none())
502 .collect();
503 if missing.is_empty() {
504 Ok(self.tiles_view())
505 } else {
506 Err(Self::missing_error(&missing))
507 }
508 }
509
510 /// The tile build with empty paths where a flag is missing: enough for
511 /// the questions that do not read a path.
512 fn tiles_view(&self) -> TilesConfig {
513 let path = |flag| self.path(flag).map(Path::to_path_buf).unwrap_or_default();
514 let mut tiles = TilesConfig::new(
515 path(PathFlag::Data),
516 path(PathFlag::NaturalEarth),
517 path(PathFlag::WaterPolygons),
518 path(PathFlag::LandPolygons),
519 path(PathFlag::Output),
520 );
521 tiles.osm_pbf.clone_from(&self.osm_pbf);
522 tiles.india_boundary.clone_from(&self.india_boundary);
523 tiles.bbox.clone_from(&self.bbox);
524 tiles.max_zoom = self.max_zoom;
525 tiles.threads = self.threads;
526 tiles.chunk_size_mb = self.chunk_size_mb;
527 tiles.tmpdir.clone_from(&self.tmpdir);
528 tiles.node_store.clone_from(&self.node_store);
529 tiles.buildings_source.clone_from(&self.buildings_source);
530 tiles.places_source.clone_from(&self.places_source);
531 tiles.divisions_source.clone_from(&self.divisions_source);
532 tiles.landcover_source.clone_from(&self.landcover_source);
533 tiles.bathymetry_source.clone_from(&self.bathymetry_source);
534 tiles.roads_source.clone_from(&self.roads_source);
535 tiles.pois_source.clone_from(&self.pois_source);
536 tiles.water_source.clone_from(&self.water_source);
537 tiles.landuse_source.clone_from(&self.landuse_source);
538 tiles.reuse = geolith_tiles_builder::Reuse::new(self.reuse.node_cache, self.reuse.resume);
539 tiles.tile_format.clone_from(&self.tile_format);
540 tiles.bridge_dir.clone_from(&self.bridge_dir);
541 tiles.no_conflate = self.no_conflate;
542 tiles.bridge_files.clone_from(&self.bridge_files);
543 tiles.reclaim_source_after_read = self.reclaim_source_after_read;
544 tiles
545 }
546}
547
548#[cfg(test)]
549mod tests {
550 use super::*;
551
552 #[test]
553 fn uses_osm_for_both() {
554 let config = Config::try_parse_from([
555 "geolith",
556 "--data",
557 "/tmp/data",
558 "--osm-pbf",
559 "/tmp/planet.osm.pbf",
560 "--natural-earth",
561 "/tmp/ne.sqlite",
562 "--water-polygons",
563 "/tmp/water",
564 "--land-polygons",
565 "/tmp/land",
566 "--output",
567 "/tmp/out.pmtiles",
568 ])
569 .expect("parse should succeed");
570
571 assert!(config.uses_osm("both"));
572 assert!(config.uses_osm("osm"));
573 assert!(!config.uses_osm("overture"));
574 assert!(config.uses_overture("both"));
575 assert!(config.uses_overture("overture"));
576 assert!(!config.uses_overture("osm"));
577 assert!(!config.has_india_boundary());
578 }
579
580 #[test]
581 fn default_source_values() {
582 let config = Config::try_parse_from([
583 "geolith",
584 "--data",
585 "/tmp/data",
586 "--osm-pbf",
587 "/tmp/planet.osm.pbf",
588 "--natural-earth",
589 "/tmp/ne.sqlite",
590 "--water-polygons",
591 "/tmp/water",
592 "--land-polygons",
593 "/tmp/land",
594 "--output",
595 "/tmp/out.pmtiles",
596 ])
597 .expect("parse should succeed");
598
599 assert_eq!(config.buildings_source, "both");
600 assert_eq!(config.places_source, "both");
601 assert_eq!(config.divisions_source, "overture");
602 assert_eq!(config.landcover_source, "overture");
603 assert_eq!(config.bathymetry_source, "overture");
604 assert_eq!(config.roads_source, "both");
605 assert_eq!(config.pois_source, "both");
606 assert_eq!(config.water_source, "both");
607 assert_eq!(config.landuse_source, "both");
608 assert_eq!(config.max_zoom, 15);
609 }
610
611 #[test]
612 fn overture_enabled_respects_source_flags() {
613 let config = Config::try_parse_from([
614 "geolith",
615 "--data",
616 "/tmp/data",
617 "--osm-pbf",
618 "/tmp/planet.osm.pbf",
619 "--natural-earth",
620 "/tmp/ne.sqlite",
621 "--water-polygons",
622 "/tmp/water",
623 "--land-polygons",
624 "/tmp/land",
625 "--output",
626 "/tmp/out.pmtiles",
627 "--buildings-source",
628 "osm",
629 "--roads-source",
630 "overture",
631 "--landcover-source",
632 "none",
633 ])
634 .expect("parse should succeed");
635
636 use crate::layers::Layer;
637
638 assert!(!config.overture_enabled(Layer::Buildings));
639 assert!(config.overture_enabled(Layer::Roads));
640 assert!(!config.overture_enabled(Layer::Landcover));
641 assert!(config.overture_enabled(Layer::Earth));
642 assert!(config.overture_enabled(Layer::Water));
643 assert!(config.overture_enabled(Layer::Pois));
644 assert!(config.overture_enabled(Layer::Landuse));
645 }
646 #[test]
647 fn osm_enabled_respects_source_flags() {
648 let config = Config::try_parse_from([
649 "geolith",
650 "--data",
651 "/tmp/data",
652 "--osm-pbf",
653 "/tmp/planet.osm.pbf",
654 "--natural-earth",
655 "/tmp/ne.sqlite",
656 "--water-polygons",
657 "/tmp/water",
658 "--land-polygons",
659 "/tmp/land",
660 "--output",
661 "/tmp/out.pmtiles",
662 "--buildings-source",
663 "overture",
664 "--roads-source",
665 "osm",
666 ])
667 .expect("parse should succeed");
668
669 use crate::layers::Layer;
670
671 assert!(!config.osm_enabled(Layer::Buildings));
672 assert!(config.osm_enabled(Layer::Roads));
673 assert!(config.osm_enabled(Layer::Earth));
674 assert!(config.osm_enabled(Layer::Water));
675 assert!(config.osm_enabled(Layer::Landuse));
676 assert!(config.osm_enabled(Layer::Pois));
677 assert!(config.osm_enabled(Layer::Places));
678 }
679
680 #[test]
681 fn osm_pbf_omitted_disables_all_osm_layers() {
682 let config = Config::try_parse_from([
683 "geolith",
684 "--data",
685 "/tmp/data",
686 "--natural-earth",
687 "/tmp/ne.sqlite",
688 "--water-polygons",
689 "/tmp/water",
690 "--land-polygons",
691 "/tmp/land",
692 "--output",
693 "/tmp/out.pmtiles",
694 ])
695 .expect("parse should succeed without --osm-pbf");
696
697 use crate::layers::Layer;
698
699 assert!(config.osm_pbf.is_none());
700 assert!(!config.osm_enabled(Layer::Buildings));
701 assert!(!config.osm_enabled(Layer::Roads));
702 assert!(!config.osm_enabled(Layer::Earth));
703 assert!(!config.osm_enabled(Layer::Water));
704 assert!(!config.osm_enabled(Layer::Landuse));
705 assert!(!config.osm_enabled(Layer::Pois));
706 assert!(!config.osm_enabled(Layer::Places));
707 assert!(!config.osm_enabled(Layer::Transit));
708 assert!(!config.osm_enabled(Layer::Boundaries));
709
710 assert!(config.overture_enabled(Layer::Buildings));
711 assert!(config.overture_enabled(Layer::Roads));
712 assert!(config.overture_enabled(Layer::Water));
713 assert!(config.overture_enabled(Layer::Landuse));
714 }
715
716 #[test]
717 fn default_output_format_is_tiles() {
718 let config = Config::try_parse_from([
719 "geolith",
720 "--data",
721 "/tmp/data",
722 "--osm-pbf",
723 "/tmp/planet.osm.pbf",
724 "--natural-earth",
725 "/tmp/ne.sqlite",
726 "--water-polygons",
727 "/tmp/water",
728 "--land-polygons",
729 "/tmp/land",
730 "--output",
731 "/tmp/out.pmtiles",
732 ])
733 .expect("parse");
734 assert_eq!(config.output_format, "tiles");
735 }
736
737 #[test]
738 fn output_format_flag_parsed() {
739 let config = Config::try_parse_from([
740 "geolith",
741 "--data",
742 "/tmp/data",
743 "--osm-pbf",
744 "/tmp/planet.osm.pbf",
745 "--natural-earth",
746 "/tmp/ne.sqlite",
747 "--water-polygons",
748 "/tmp/water",
749 "--land-polygons",
750 "/tmp/land",
751 "--output",
752 "/tmp/out.pmtiles",
753 "--output-format",
754 "routing",
755 ])
756 .expect("parse");
757 assert_eq!(config.output_format, "routing");
758 }
759
760 /// The `--schema` flag is gone: tiles always follow the protomaps
761 /// basemap schema, so an old script that still passes it fails loudly.
762 #[test]
763 fn schema_flag_is_refused() {
764 let err = Config::try_parse_from([
765 "geolith",
766 "--data",
767 "/tmp/data",
768 "--natural-earth",
769 "/tmp/ne.sqlite",
770 "--water-polygons",
771 "/tmp/water",
772 "--land-polygons",
773 "/tmp/land",
774 "--output",
775 "/tmp/out.pmtiles",
776 "--schema",
777 "protomaps",
778 ])
779 .expect_err("--schema is no longer a flag");
780 assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
781 }
782
783 #[test]
784 fn osrm_output_is_no_longer_a_flag() {
785 let err = Config::try_parse_from([
786 "geolith",
787 "--data",
788 "/tmp/data",
789 "--natural-earth",
790 "/tmp/ne.sqlite",
791 "--water-polygons",
792 "/tmp/water",
793 "--land-polygons",
794 "/tmp/land",
795 "--output",
796 "/tmp/out.pmtiles",
797 "--osrm-output",
798 "/tmp/routing.osrm.tar",
799 ])
800 .expect_err("the OSRM writer was removed");
801 assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
802 }
803}