use clap::Parser;
#[derive(Parser, Debug)]
#[command(name = "runzip")]
#[command(version)]
#[command(about = "A Rust unzip utility with HTTP URL support", long_about = None)]
#[command(after_help = "Examples:\n \
runzip data1.zip -x joe extract all files except joe from data1.zip\n \
runzip -p foo.zip | more send contents of foo.zip via pipe into more\n \
runzip -l https://example.com/archive.zip list files from remote ZIP")]
pub struct Cli {
#[arg(value_name = "FILE")]
pub file: String,
#[arg(value_name = "FILES")]
pub files: Vec<String>,
#[arg(short = 'l')]
pub list: bool,
#[arg(short = 'v')]
pub verbose: bool,
#[arg(short = 'p')]
pub pipe: bool,
#[arg(short = 'd', value_name = "DIR")]
pub extract_dir: Option<String>,
#[arg(short = 'x', value_name = "FILE", num_args = 1..)]
pub exclude: Vec<String>,
#[arg(short = 'n')]
pub never_overwrite: bool,
#[arg(short = 'o')]
pub overwrite: bool,
#[arg(short = 'j')]
pub junk_paths: bool,
#[arg(short = 'q', action = clap::ArgAction::Count)]
pub quiet: u8,
}
impl Cli {
pub fn is_http_url(&self) -> bool {
self.file.starts_with("http://") || self.file.starts_with("https://")
}
pub fn is_quiet(&self) -> bool {
self.quiet > 0 || self.pipe
}
pub fn is_very_quiet(&self) -> bool {
self.quiet > 1
}
}