pigeon-cli 0.4.0

Pigeon: authenticate, sink, and transform personal data from external services.
Documentation
use clap::{Args, Subcommand};

use crate::commands::keyring::email::provider::Provider;
use crate::core::observability::Observable;

#[derive(Args, Debug)]
pub struct KeyringArgs {
    #[command(subcommand)]
    pub command: KeyringCommands,
}

#[derive(Subcommand, Debug)]
pub enum KeyringCommands {
    /// Add a new email identity, bucket-config, or encryption key
    Add(AddArgs),
    /// Edit an existing entry's fields
    Modify {
        /// Alias of the entry to edit. Interactively selected from every
        /// configured entry (of any kind) when omitted.
        alias: Option<String>,
    },
    /// Remove a configured entry and its secret
    Delete {
        /// Alias of the entry to remove.
        alias: String,
    },
    /// List every configured entry
    List,
}

impl Observable for KeyringCommands {
    fn command_name(&self) -> &'static str {
        match self {
            KeyringCommands::Add(_) => "keyring.add",
            KeyringCommands::Modify { .. } => "keyring.modify",
            KeyringCommands::Delete { .. } => "keyring.delete",
            KeyringCommands::List => "keyring.list",
        }
    }
}

#[derive(Args, Debug)]
pub struct AddArgs {
    #[command(subcommand)]
    pub kind: Option<AddKind>,
}

#[derive(Subcommand, Debug)]
pub enum AddKind {
    /// Authenticate an email identity and register it under a local alias
    Email {
        /// Email address of the identity to authenticate, e.g. first.last@example.com
        email: String,

        /// Local alias to store this identity under (e.g. first-last).
        /// Defaults to a sanitized form of the email's local part.
        #[arg(long)]
        alias: Option<String>,

        /// Email provider. Auto-detected from the email's domain when
        /// omitted, falling back to an interactive prompt if detection fails.
        #[arg(long)]
        provider: Option<Provider>,

        /// IMAP host, e.g. imap.example.com. Required when --provider is
        /// "custom" (or resolves to it); ignored for known providers, which
        /// use their own well-known host.
        #[arg(long)]
        host: Option<String>,

        /// IMAP port. Defaults to 993 for a custom provider when omitted;
        /// ignored for known providers, which use their own well-known port.
        #[arg(long)]
        port: Option<u16>,
    },

    /// Interactively configure a new S3-compatible bucket-config
    Bucket {
        /// Alias to register this bucket-config under (e.g. "backup").
        /// Prompted if omitted.
        alias: Option<String>,
    },

    /// Register a new symmetric encryption key, generated or imported
    /// (ADR-0026)
    EncryptionKey {
        /// Alias to register this key under (e.g. "primary"). Prompted if
        /// omitted.
        alias: Option<String>,
    },
}