use anyhow::{Context, Result as AnyResult};
use clap::{Parser, ValueEnum};
use h3o::CellIndex;
#[derive(Parser, Debug)]
pub struct Args {
#[arg(short, long, value_enum, default_value_t = Format::Text)]
format: Format,
#[arg(short, long, default_value_t = false)]
pretty: bool,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
enum Format {
Text,
Json,
}
pub fn run(args: &Args) -> AnyResult<()> {
let indexes =
crate::io::read_cell_indexes().collect::<AnyResult<Vec<_>>>()?;
let compacted = CellIndex::compact(indexes).context("compaction")?;
match args.format {
Format::Text => {
for index in compacted {
println!("{index}");
}
}
Format::Json => {
let compacted = compacted
.into_iter()
.map(Into::into)
.collect::<Vec<crate::json::CellIndex>>();
crate::json::print(&compacted, args.pretty)?;
}
}
Ok(())
}