use anyhow::Result;
use clap::{Parser, Subcommand};
use encoding_rs::Encoding;
use thiserror::Error as ThisError;
use crate::{convert::Convert, decrypt::Decrypt, show::Show, show_pc::ShowPc, show_por::ShowPor};
mod convert;
mod decrypt;
mod show;
mod show_pc;
mod show_por;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand, Clone, Debug)]
enum Command {
Convert(Convert),
Decrypt(Decrypt),
Show(Show),
ShowPor(ShowPor),
ShowPc(ShowPc),
}
impl Command {
fn run(self) -> Result<()> {
match self {
Command::Convert(convert) => convert.run(),
Command::Decrypt(decrypt) => decrypt.run(),
Command::Show(show) => show.run(),
Command::ShowPor(show_por) => show_por.run(),
Command::ShowPc(show_pc) => show_pc.run(),
}
}
}
#[derive(ThisError, Debug)]
#[error("{0}: unknown encoding")]
struct UnknownEncodingError(String);
fn parse_encoding(arg: &str) -> Result<&'static Encoding, UnknownEncodingError> {
match Encoding::for_label_no_replacement(arg.as_bytes()) {
Some(encoding) => Ok(encoding),
None => Err(UnknownEncodingError(arg.to_string())),
}
}
fn main() -> Result<()> {
Cli::parse().command.run()
}