qcert 0.1.3

A tool for generating test key/certificate pairs
use clap::{ArgAction, Args, Parser, Subcommand};

#[derive(Debug, Args)]
pub struct GlobalOpts {
  /// Enable verbose output.
  #[arg(short, long, global = true, action = ArgAction::Count)]
  pub verbose: u8
}

#[derive(Debug, Parser)]
#[command(name = env!("CARGO_PKG_NAME"))]
#[command(version = env!("CARGO_PKG_VERSION"))]
#[command(about = env!("CARGO_PKG_DESCRIPTION"))]
pub struct Cli {
  #[command(subcommand)]
  pub command: Cmd,

  #[command(flatten)]
  pub global: GlobalOpts
}

#[derive(Debug, Subcommand)]
pub enum Cmd {
  /// Create a new CA key and self-signed certificate.
  ///
  /// This will create the files `ca.key.pem` and `ca.cert.pem` in the current
  /// directory.
  #[command(visible_alias("mkca"))]
  MkCa(MkCaCmd),

  /// Create a server key and certificate.
  ///
  /// It is assumed that the files `ca.key.pem` and `ca.cert.pem` exist in the
  /// current directory.
  ///
  /// On success this subcommand files `<NAME>.key.pem` and `<NAME>.cert.pem`
  /// in the current directory.
  #[command(arg_required_else_help = true, visible_alias("mksrv"))]
  MkSrv(MkSrvCmd)
}

#[derive(Debug, Args)]
pub struct MkCaCmd {
  /// Overwrite key/certificate files if they already exist.
  #[arg(short, long)]
  pub force: bool
}

#[derive(Debug, Args)]
pub struct MkSrvCmd {
  /// Overwrite key/certificate files if they already exist.
  #[arg(short, long)]
  pub force: bool,

  /// Add a domain or ip address to the certificate.
  #[arg(short, long)]
  pub domain: Vec<String>,

  /// Set certificate name.
  ///
  /// Will be used to set the certificate's `commonName` field, as well as the
  /// file name stem for output files.
  #[arg(value_name = "NAME")]
  pub name: String
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :