use crate::commands::command::Cmd;
use clap::{Parser, Subcommand};
use openssl::version::version;
pub mod utils;
pub mod commands;
pub mod error;
#[derive(Parser)]
#[command(name = "keytool")]
#[command(about = "Rust Keytool — Manage certificates and keystores")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Genkeypair(commands::genkeypair::GenKeyPairCmd),
Genseckey(commands::genseckey::GenSecKeyCmd),
Certreq(commands::certreq::CertReqCmd),
Gencert(commands::gencert::GenCertCmd),
Exportcert(commands::exportcert::ExportCertCmd),
Importcert(commands::importcert::ImportCertCmd),
Importkeystore(commands::importkeystore::ImportKeyStoreCmd),
Delete(commands::delete::DeleteCmd),
Changealias(commands::changealias::ChangeAliasCmd),
Keypasswd(commands::keypasswd::KeyPasswdCmd),
List(commands::list::ListCmd),
Printcert(commands::printcert::PrintCertCmd),
Printcertreq(commands::printcertreq::PrintCertReqCmd),
Printcrl(commands::printcrl::PrintCRLCmd),
Storepasswd(commands::storepasswd::StorePasswdCmd),
Showinfo(commands::showinfo::ShowInfoCmd),
}
fn main() {
println!("OpenSSL version: {}", version());
let cli = Cli::parse();
let result = match cli.command {
Commands::Genkeypair(cmd) => cmd.run(),
Commands::Genseckey(cmd) => cmd.run(),
Commands::Certreq(cmd) => cmd.run(),
Commands::Gencert(cmd) => cmd.run(),
Commands::Exportcert(cmd) => cmd.run(),
Commands::Importcert(cmd) => cmd.run(),
Commands::Importkeystore(cmd) => cmd.run(),
Commands::Delete(cmd) => cmd.run(),
Commands::Changealias(cmd) => cmd.run(),
Commands::Keypasswd(cmd) => cmd.run(),
Commands::List(cmd) => cmd.run(),
Commands::Printcert(cmd) => cmd.run(),
Commands::Printcertreq(cmd) => cmd.run(),
Commands::Printcrl(cmd) => cmd.run(),
Commands::Storepasswd(cmd) => cmd.run(),
Commands::Showinfo(cmd) => cmd.run(),
};
if let Err(e) = result {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}