forge/cli/
mod.rs

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    /// Path to the PFX/P12 file
14    #[arg(long, required = true, help = "Path to the PFX/P12 certificate file")]
15    pub pfx: String,
16
17    /// Password for the PFX/P12 file
18    #[arg(long, help = "Password for the PFX file (if password-protected)")]
19    pub password: Option<String>,
20
21    /// Output directory for PEM files (defaults to current directory)
22    #[arg(long, help = "Output directory for generated PEM files")]
23    out: Option<String>,
24
25    /// Generate a combined PEM file with both certificate and private key
26    #[arg(
27        long,
28        help = "Create a combined PEM file containing both private key and certificate"
29    )]
30    pub combined: bool,
31
32    /// Custom filename for the private key (defaults to private_key.pem)
33    #[arg(long, help = "Custom filename for the private key output")]
34    pub key_file: Option<String>,
35
36    /// Custom filename for the certificate (defaults to certificate.pem)
37    #[arg(long, help = "Custom filename for the certificate output")]
38    pub cert_file: Option<String>,
39
40    /// Custom filename for the combined file (defaults to certificate_with_key.pem)
41    #[arg(long, help = "Custom filename for the combined PEM file")]
42    pub combined_file: Option<String>,
43
44    /// Extract all certificates in the chain (not just the main certificate)
45    #[arg(long, help = "Extract and save the complete certificate chain")]
46    pub chain: bool,
47
48    /// Verbose output
49    #[arg(long, help = "Enable verbose output with detailed information")]
50    pub verbose: bool,
51}
52
53impl Args {
54    /// Get the password, defaulting to empty string if none provided
55    pub fn password(&self) -> &str {
56        self.password.as_deref().unwrap_or("")
57    }
58
59    /// Get the output directory, defaulting to current directory
60    pub fn output_dir(&self) -> &str {
61        self.out.as_deref().unwrap_or(".")
62    }
63
64    /// Get the private key filename, with default
65    pub fn key_filename(&self) -> &str {
66        self.key_file.as_deref().unwrap_or("private_key.pem")
67    }
68
69    /// Get the certificate filename, with default
70    pub fn cert_filename(&self) -> &str {
71        self.cert_file.as_deref().unwrap_or("certificate.pem")
72    }
73
74    /// Get the combined file filename, with default
75    pub fn combined_filename(&self) -> &str {
76        self.combined_file
77            .as_deref()
78            .unwrap_or("certificate_with_key.pem")
79    }
80}