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