h3o_cli/commands/
compact.rs1use anyhow::{Context, Result as AnyResult};
4use clap::{Parser, ValueEnum};
5use h3o::CellIndex;
6
7#[derive(Parser, Debug)]
11pub struct Args {
12 #[arg(short, long, value_enum, default_value_t = Format::Text)]
14 format: Format,
15
16 #[arg(short, long, default_value_t = false)]
18 pretty: bool,
19}
20
21#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
22enum Format {
23 Text,
24 Json,
25}
26
27pub fn run(args: &Args) -> AnyResult<()> {
29 let indexes =
30 crate::io::read_cell_indexes().collect::<AnyResult<Vec<_>>>()?;
31
32 let compacted = CellIndex::compact(indexes).context("compaction")?;
33 match args.format {
34 Format::Text => {
35 for index in compacted {
36 println!("{index}");
37 }
38 }
39 Format::Json => {
40 let compacted = compacted
41 .into_iter()
42 .map(Into::into)
43 .collect::<Vec<crate::json::CellIndex>>();
44 crate::json::print(&compacted, args.pretty)?;
45 }
46 }
47
48 Ok(())
49}