use std::ffi::OsString;
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
use dream_archivetool::{ArchiveFormat, Ba2ArchiveKind, Ba2Version, Tes4Version};
#[derive(Debug, Parser)]
#[command(
author,
version,
about = "Inspect and manipulate Bethesda BSA and BA2 archives"
)]
pub(super) struct Cli {
#[arg(long, value_name = "SHELL", conflicts_with = "generate_manpage")]
pub(super) generate_completion: Option<Shell>,
#[arg(long, conflicts_with = "generate_completion")]
pub(super) generate_manpage: bool,
#[command(subcommand)]
pub(super) command: Option<Command>,
}
#[derive(Debug, Subcommand)]
pub(super) enum Command {
Info {
archive: PathBuf,
#[arg(long)]
json: bool,
},
List {
archive: PathBuf,
#[arg(short, long, conflicts_with = "json")]
long: bool,
#[arg(long)]
json: bool,
},
Verify {
archive: PathBuf,
#[arg(long)]
read_payloads: bool,
#[arg(long)]
json: bool,
},
Diff {
old: PathBuf,
new: PathBuf,
#[arg(long)]
hash: bool,
#[arg(long)]
json: bool,
},
Extract {
archive: PathBuf,
#[arg(required_unless_present = "entry_hex", conflicts_with = "entry_hex")]
entry: Option<OsString>,
#[arg(long, value_name = "HEX", conflicts_with = "entry")]
entry_hex: Option<String>,
#[arg(short, long, conflicts_with = "stdout")]
output: Option<PathBuf>,
#[arg(
long,
conflicts_with_all = ["output", "flat", "overwrite", "skip_existing", "fsync"]
)]
stdout: bool,
#[arg(long, conflicts_with = "stdout")]
fsync: bool,
#[arg(long, conflicts_with = "stdout")]
flat: bool,
#[arg(long, conflicts_with_all = ["skip_existing", "stdout"])]
overwrite: bool,
#[arg(long, conflicts_with_all = ["overwrite", "stdout"])]
skip_existing: bool,
#[arg(long, conflicts_with = "stdout")]
json: bool,
},
ExtractAll {
archive: PathBuf,
#[arg(short, long)]
output: Option<PathBuf>,
#[arg(long, conflicts_with = "skip_existing")]
overwrite: bool,
#[arg(long, conflicts_with = "overwrite")]
skip_existing: bool,
#[arg(long)]
json: bool,
#[arg(long)]
dry_run: bool,
#[arg(long)]
fsync: bool,
},
Create {
archive: PathBuf,
input: PathBuf,
#[arg(long, value_enum)]
format: CliArchiveFormat,
#[arg(long, value_enum)]
tes4_version: Option<CliTes4Version>,
#[arg(long, value_enum)]
ba2_kind: Option<CliBa2ArchiveKind>,
#[arg(long, value_enum)]
ba2_version: Option<CliBa2Version>,
#[arg(long)]
compress: bool,
#[arg(long)]
json: bool,
#[arg(long)]
dry_run: bool,
#[arg(long)]
fsync: bool,
#[arg(long)]
follow_symlinks: bool,
},
Add {
archive: PathBuf,
#[arg(required = true)]
inputs: Vec<PathBuf>,
#[arg(short, long)]
output: Option<PathBuf>,
#[arg(long)]
json: bool,
#[arg(long)]
dry_run: bool,
#[arg(long)]
fsync: bool,
#[arg(long)]
follow_symlinks: bool,
},
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub(super) enum CliArchiveFormat {
Tes3,
Tes4,
Ba2,
}
impl From<CliArchiveFormat> for ArchiveFormat {
fn from(format: CliArchiveFormat) -> Self {
match format {
CliArchiveFormat::Tes3 => Self::Tes3,
CliArchiveFormat::Tes4 => Self::Tes4,
CliArchiveFormat::Ba2 => Self::Ba2,
}
}
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub(super) enum CliTes4Version {
Oblivion,
Fallout3,
Skyrim,
SkyrimSe,
}
impl From<CliTes4Version> for Tes4Version {
fn from(version: CliTes4Version) -> Self {
match version {
CliTes4Version::Oblivion => Self::Oblivion,
CliTes4Version::Fallout3 => Self::Fallout3,
CliTes4Version::Skyrim => Self::Skyrim,
CliTes4Version::SkyrimSe => Self::SkyrimSe,
}
}
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub(super) enum CliBa2ArchiveKind {
Gnrl,
Dx10,
Gnmf,
}
impl From<CliBa2ArchiveKind> for Ba2ArchiveKind {
fn from(kind: CliBa2ArchiveKind) -> Self {
match kind {
CliBa2ArchiveKind::Gnrl => Self::Gnrl,
CliBa2ArchiveKind::Dx10 => Self::Dx10,
CliBa2ArchiveKind::Gnmf => Self::Gnmf,
}
}
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub(super) enum CliBa2Version {
Fallout4,
Starfield,
Fallout4NextGen,
}
impl From<CliBa2Version> for Ba2Version {
fn from(version: CliBa2Version) -> Self {
match version {
CliBa2Version::Fallout4 => Self::Fallout4,
CliBa2Version::Starfield => Self::Starfield,
CliBa2Version::Fallout4NextGen => Self::Fallout4NextGen,
}
}
}