1use clap::Parser;
2
3#[derive(Parser, Debug)]
4#[command(
5 name = "forge",
6 author = "Nick Hudson <nick.hudson@gmail.com>",
7 version = "0.1.0",
8 about = "Convert PFX/P12 certificate files to PEM format",
9 long_about = "A Rust-based tool for converting PFX (PKCS#12) certificate files to PEM format. \
10 Supports password-protected files, certificate chains, and various output options."
11)]
12pub struct Args {
13 #[arg(long, required = true, help = "Path to the PFX/P12 certificate file")]
15 pub pfx: String,
16
17 #[arg(long, help = "Password for the PFX file (if password-protected)")]
19 pub password: Option<String>,
20
21 #[arg(long, help = "Output directory for generated PEM files")]
23 out: Option<String>,
24
25 #[arg(
27 long,
28 help = "Create a combined PEM file containing both private key and certificate"
29 )]
30 pub combined: bool,
31
32 #[arg(long, help = "Custom filename for the private key output")]
34 pub key_file: Option<String>,
35
36 #[arg(long, help = "Custom filename for the certificate output")]
38 pub cert_file: Option<String>,
39
40 #[arg(long, help = "Custom filename for the combined PEM file")]
42 pub combined_file: Option<String>,
43
44 #[arg(long, help = "Extract and save the complete certificate chain")]
46 pub chain: bool,
47
48 #[arg(long, help = "Enable verbose output with detailed information")]
50 pub verbose: bool,
51}
52
53impl Args {
54 pub fn password(&self) -> &str {
56 self.password.as_deref().unwrap_or("")
57 }
58
59 pub fn output_dir(&self) -> &str {
61 self.out.as_deref().unwrap_or(".")
62 }
63
64 pub fn key_filename(&self) -> &str {
66 self.key_file.as_deref().unwrap_or("private_key.pem")
67 }
68
69 pub fn cert_filename(&self) -> &str {
71 self.cert_file.as_deref().unwrap_or("certificate.pem")
72 }
73
74 pub fn combined_filename(&self) -> &str {
76 self.combined_file
77 .as_deref()
78 .unwrap_or("certificate_with_key.pem")
79 }
80}