use clap::Parser; use clap::Subcommand; #[derive(Parser, Debug)] #[clap( name = "Husk milter", about = "Encrypting milter.", arg_required_else_help = true, )] pub struct CliArgs { #[clap( long, short, global = true, help = "Configuration file.", )] pub config: Option, #[clap(subcommand)] pub subcommand: HuskSubcommands, } // Subcommands Level 1 #[derive(Debug, Subcommand)] pub enum HuskSubcommands { Daemon(DaemonCommand), Introducer(IntroducerCommand), Local(LocalCommand), } // Daemon subcommands #[derive(Parser, Debug)] #[clap( name = "daemon", about = "Manage milter daemon.", subcommand_required = true, arg_required_else_help = true, disable_colored_help = true, disable_version_flag = true, )] pub struct DaemonCommand { #[clap(subcommand)] pub subcommand: DaemonSubcommand, } #[derive(Debug, Subcommand)] pub enum DaemonSubcommand { Start, Stop, Status } // Introducer subcommands #[derive(Parser, Debug)] #[clap( name = "introducer", about = "Manage introducers.", subcommand_required = true, arg_required_else_help = true, disable_colored_help = true, disable_version_flag = true, )] pub struct IntroducerCommand { #[clap(subcommand)] pub subcommand: IntroducerSubcommand, } #[derive(Debug, Subcommand)] pub enum IntroducerSubcommand { Add(IntroducerAddCommand), Remove(IntroducerRemoveCommand), List } #[derive(Parser, Debug)] #[clap( name = "introducer", about = "Add introducers.", )] pub struct IntroducerAddCommand { #[clap( long = "cert", help = "Certificate to declare as introducer.", conflicts_with = "cert_file" )] pub cert: Option, #[clap( long = "cert-file", help = "Import certificate from CERT_FILE and declare it as introducer.", value_name = "CERT_FILE", conflicts_with = "cert" )] pub cert_file: Option, #[clap( long = "domains", help = "Domains this certificate introduces.", required = true, num_args = 1.., value_delimiter = ' ' )] pub domains: Vec, } #[derive(Parser, Debug)] #[clap( name = "introducer", about = "Remove introducers.", )] pub struct IntroducerRemoveCommand { #[clap( long = "cert", help = "Certificate to be removed as introducer." )] pub cert: String, #[clap( long = "demote", help = "Remove introducing capabilities, but keep certificate authenticated.", default_value_t = false, )] pub demote: bool, } // Local subcommands #[derive(Parser, Debug)] #[clap( name = "local", about = "Manage manually added certificates.", subcommand_required = true, arg_required_else_help = true, disable_colored_help = true, disable_version_flag = true, )] pub struct LocalCommand { #[clap(subcommand)] pub subcommand: LocalSubcommand, } #[derive(Debug, Subcommand)] pub enum LocalSubcommand { Add(LocalAddCommand), Remove(LocalRemoveCommand), List } #[derive(Parser, Debug)] #[clap( name = "local_add", about = "Add an authenticated certificate.", )] pub struct LocalAddCommand { #[clap( long = "cert", help = "Certificate to add." )] pub cert_file: String, } #[derive(Parser, Debug)] #[clap( name = "local_remove", about = "Certificate to remove.", )] pub struct LocalRemoveCommand { #[clap( long = "cert", help = "Certificate to removed." )] pub cert: String, }