use clap::Parser;
#[derive(Parser, Debug)]
#[command(
name = "forge",
author = "Nick Hudson <nick.hudson@gmail.com>",
version = "0.1.1",
about = "Convert PFX/P12 certificate files to PEM format",
long_about = "A Rust-based tool for converting PFX (PKCS#12) certificate files to PEM format. \
Supports password-protected files, certificate chains, and various output options."
)]
pub struct Args {
#[arg(long, required = true, help = "Path to the PFX/P12 certificate file")]
pub pfx: String,
#[arg(long, help = "Password for the PFX file (if password-protected)")]
pub password: Option<String>,
#[arg(long, help = "Output directory for generated PEM files")]
out: Option<String>,
#[arg(
long,
help = "Create a combined PEM file containing both private key and certificate"
)]
pub combined: bool,
#[arg(long, help = "Custom filename for the private key output")]
pub key_file: Option<String>,
#[arg(long, help = "Custom filename for the certificate output")]
pub cert_file: Option<String>,
#[arg(long, help = "Custom filename for the combined PEM file")]
pub combined_file: Option<String>,
#[arg(long, help = "Extract and save the complete certificate chain")]
pub chain: bool,
#[arg(long, help = "Enable verbose output with detailed information")]
pub verbose: bool,
}
impl Args {
pub fn password(&self) -> &str {
self.password.as_deref().unwrap_or("")
}
pub fn output_dir(&self) -> &str {
self.out.as_deref().unwrap_or(".")
}
pub fn key_filename(&self) -> &str {
self.key_file.as_deref().unwrap_or("private_key.pem")
}
pub fn cert_filename(&self) -> &str {
self.cert_file.as_deref().unwrap_or("certificate.pem")
}
pub fn combined_filename(&self) -> &str {
self.combined_file
.as_deref()
.unwrap_or("certificate_with_key.pem")
}
}