use anyhow::Result;
use clap::{Parser, Subcommand};
use oliver::{DataFileType, convert, convert_all, pack, parse, unpack};
use std::{path::PathBuf, process::ExitCode};
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true), author, version, about)]
struct Cli {
#[clap(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
Convert(Convert),
ConvertAll(ConvertAll),
Pack(Pack),
Parse(Parse),
Unpack(Unpack),
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Convert {
#[clap(short, long, required = true)]
from: PathBuf,
#[clap(short, long, required = true)]
to: PathBuf,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct ConvertAll {
#[clap(short, long, required = true)]
path: PathBuf,
#[clap(short, long, required = true)]
from: DataFileType,
#[clap(short, long, required = true)]
to: DataFileType,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Parse {
paths: Vec<PathBuf>,
#[clap(long, short)]
verbose: bool,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Pack {
#[clap()]
mod_files_root: PathBuf,
#[clap(long, short)]
destination: Option<PathBuf>,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Unpack {
#[clap()]
mod_file_path: PathBuf,
#[clap(long, short)]
destination: Option<PathBuf>,
}
fn run() -> Result<()> {
match Cli::parse().command {
Command::Parse(Parse { paths, verbose }) => parse(paths, verbose),
Command::Pack(Pack {
mod_files_root,
destination,
}) => pack(mod_files_root, destination),
Command::Unpack(Unpack {
mod_file_path,
destination,
}) => unpack(&mod_file_path, destination),
Command::Convert(Convert { from, to }) => convert(&from, &to),
Command::ConvertAll(ConvertAll { path, from, to }) => convert_all(path, from, to),
}
}
fn main() -> ExitCode {
match run() {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("{e}");
ExitCode::FAILURE
}
}
}