use clap::Parser;
use hadris_iso::write::options::BaseIsoLevel;
use std::{path::PathBuf, str::FromStr};
#[derive(Debug, Clone, Parser)]
#[command(name = "hadris-iso")]
#[command(author, version, about = "ISO 9660 filesystem utility", long_about = None)]
pub struct Args {
#[command(subcommand)]
pub cmd: Command,
}
#[derive(Debug, Clone, clap::Subcommand)]
pub enum Command {
Info(InfoArgs),
Ls(LsArgs),
Tree(TreeArgs),
Extract(ExtractArgs),
Create(CreateArgs),
Verify(VerifyArgs),
#[command(name = "mkisofs", alias = "xorriso")]
Mkisofs(MkisofsArgs),
Cat(CatArgs),
}
#[derive(Debug, Clone, Parser)]
pub struct InfoArgs {
pub input: PathBuf,
#[arg(short, long)]
pub verbose: bool,
}
#[derive(Debug, Clone, Parser)]
pub struct LsArgs {
pub input: PathBuf,
#[arg(default_value = "/")]
pub path: String,
#[arg(short, long)]
pub long: bool,
#[arg(short, long)]
pub all: bool,
}
#[derive(Debug, Clone, Parser)]
pub struct TreeArgs {
pub input: PathBuf,
#[arg(default_value = "/")]
pub path: String,
#[arg(short, long)]
pub depth: Option<usize>,
}
#[derive(Debug, Clone, Parser)]
pub struct ExtractArgs {
pub input: PathBuf,
#[arg(short, long, default_value = ".")]
pub output: PathBuf,
#[arg(short, long)]
pub path: Option<String>,
#[arg(short, long)]
pub verbose: bool,
}
#[derive(Debug, Clone, Parser)]
pub struct CreateArgs {
pub source: PathBuf,
#[arg(short, long)]
pub output: PathBuf,
#[arg(short = 'V', long, default_value = "CDROM")]
pub volume_name: String,
#[arg(short, long, default_value = "1")]
pub level: ArgLevel,
#[arg(short = 'J', long)]
pub joliet: bool,
#[arg(short = 'R', long)]
pub rock_ridge: bool,
#[arg(short, long)]
pub boot: Option<String>,
#[arg(long)]
pub efi_boot: Option<String>,
#[arg(long, default_value = "4")]
pub boot_load_size: u16,
#[arg(long)]
pub boot_info_table: bool,
#[arg(long)]
pub hybrid_mbr: bool,
#[arg(long)]
pub hybrid_gpt: bool,
#[arg(long, alias = "sysid")]
pub system_id: Option<String>,
#[arg(long, alias = "volset")]
pub volume_set_id: Option<String>,
#[arg(long, alias = "publisher")]
pub publisher_id: Option<String>,
#[arg(long, alias = "preparer")]
pub preparer_id: Option<String>,
#[arg(long, alias = "appid")]
pub application_id: Option<String>,
#[arg(long)]
pub strict_charset: bool,
#[arg(short, long)]
pub verbose: bool,
#[arg(long)]
pub dry_run: bool,
}
#[derive(Debug, Clone, Parser)]
pub struct VerifyArgs {
pub input: PathBuf,
#[arg(short, long)]
pub verbose: bool,
#[arg(short, long)]
pub strict: bool,
}
#[derive(Debug, Clone, Parser)]
pub struct MkisofsArgs {
pub source: PathBuf,
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(short = 'V')]
pub volume_name: Option<String>,
#[arg(short = 'J')]
pub joliet: bool,
#[arg(short = 'R')]
pub rock_ridge: bool,
#[arg(short = 'b')]
pub boot_image: Option<String>,
#[arg(long = "no-emul-boot")]
pub no_emul_boot: bool,
#[arg(long = "boot-load-size")]
pub boot_load_size: Option<u16>,
#[arg(long = "boot-info-table")]
pub boot_info_table: bool,
#[arg(short = 'e', long = "efi-boot")]
pub efi_boot: Option<String>,
#[arg(long = "isohybrid-mbr")]
pub isohybrid_mbr: Option<PathBuf>,
}
#[derive(Debug, Clone, Parser)]
pub struct CatArgs {
pub input: PathBuf,
pub path: String,
}
#[derive(Debug, Clone)]
pub struct ArgLevel(pub BaseIsoLevel);
impl Default for ArgLevel {
fn default() -> Self {
Self(BaseIsoLevel::Level1 {
supports_lowercase: false,
supports_rrip: false,
})
}
}
impl FromStr for ArgLevel {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"1" => Self(BaseIsoLevel::Level1 {
supports_lowercase: false,
supports_rrip: false,
}),
"2" => Self(BaseIsoLevel::Level2 {
supports_lowercase: false,
supports_rrip: false,
}),
"1l" => Self(BaseIsoLevel::Level1 {
supports_lowercase: true,
supports_rrip: false,
}),
"2l" => Self(BaseIsoLevel::Level2 {
supports_lowercase: true,
supports_rrip: false,
}),
"3" => Self(BaseIsoLevel::Level2 {
supports_lowercase: true,
supports_rrip: false,
}),
_ => return Err("invalid level (use 1, 2, 1l, 2l, or 3)"),
})
}
}