use clap::{Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(
name = "zexc",
version,
about = "zexc — compress/decompress .zex files",
long_about = "ZEX compression tool (command: zexc, files: *.zex)\n\n\
Examples:\n \
zexc compress input.txt output.zex\n \
zexc decompress output.zex recovered.txt\n \
zexc info file.zex\n \
zexc test file.zex\n \
cat data | zexc compress - - > data.zex\n \
zexc archive create bundle.zexa a.txt b.bin\n \
zexc train-dict http.dict samples/*\n\n\
License: GNU General Public License v3 only (GPL-3.0-only).\n\
Copyright (C) 2026 Ali Zain <alizain@zainiumdynamics.tech>\n\
Website: https://zainiumdynamics.tech\n\
This is free software with ABSOLUTELY NO WARRANTY."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
#[arg(short = 'T', long = "threads", global = true, default_value_t = 0)]
pub threads: usize,
#[arg(short = 'q', long, global = true)]
pub quiet: bool,
}
#[derive(Debug, Subcommand)]
pub enum Commands {
Compress {
input: PathBuf,
output: Option<PathBuf>,
#[arg(short = 'l', long, default_value_t = 3)]
level: u8,
#[arg(short = 'm', long, value_enum, default_value_t = ModeArg::Balanced)]
mode: ModeArg,
#[arg(long)]
no_checksum: bool,
#[arg(long)]
secure: bool,
#[arg(short = 'e', long)]
password: Option<String>,
#[arg(short = 'D', long)]
dict: Option<PathBuf>,
#[arg(long, default_value_t = 256)]
block_size_kib: u32,
#[arg(long)]
rm: bool,
},
Decompress {
input: PathBuf,
output: Option<PathBuf>,
#[arg(long)]
no_check: bool,
#[arg(long)]
secure: bool,
#[arg(short = 'e', long)]
password: Option<String>,
#[arg(short = 'D', long)]
dict: Option<PathBuf>,
#[arg(long)]
rm: bool,
},
Info {
input: PathBuf,
},
Test {
input: PathBuf,
#[arg(short = 'e', long)]
password: Option<String>,
#[arg(short = 'D', long)]
dict: Option<PathBuf>,
},
TrainDict {
output: PathBuf,
samples: Vec<PathBuf>,
#[arg(long, default_value_t = 112_640)]
max_size: usize,
#[arg(long)]
simple: bool,
#[arg(long, default_value_t = 8)]
d: usize,
},
SeekCompress {
input: PathBuf,
output: PathBuf,
#[arg(long, default_value_t = 256)]
frame_kib: u32,
#[arg(short = 'l', long, default_value_t = 3)]
level: u8,
#[arg(short = 'm', long, value_enum, default_value_t = ModeArg::Balanced)]
mode: ModeArg,
},
Archive {
#[command(subcommand)]
action: ArchiveCmd,
},
Bench {
input: PathBuf,
#[arg(short = 'l', long, default_value_t = 3)]
level: u8,
#[arg(short = 'm', long, value_enum, default_value_t = ModeArg::Balanced)]
mode: ModeArg,
#[arg(long, default_value_t = 5)]
iters: u32,
},
}
#[derive(Debug, Subcommand)]
pub enum ArchiveCmd {
Create {
output: PathBuf,
files: Vec<PathBuf>,
#[arg(short = 'l', long, default_value_t = 3)]
level: u8,
#[arg(short = 'm', long, value_enum, default_value_t = ModeArg::Balanced)]
mode: ModeArg,
},
List {
archive: PathBuf,
},
Extract {
archive: PathBuf,
dir: PathBuf,
},
}
#[derive(Debug, Clone, Copy, ValueEnum, Default)]
pub enum ModeArg {
Turbo,
#[default]
Balanced,
Max,
}
impl From<ModeArg> for crate::format::header::CompressionMode {
fn from(m: ModeArg) -> Self {
match m {
ModeArg::Turbo => Self::Turbo,
ModeArg::Balanced => Self::Balanced,
ModeArg::Max => Self::Max,
}
}
}