Skip to main content

pigeon/commands/keyring/
cli.rs

1use clap::{Args, Subcommand};
2
3use crate::commands::keyring::email::provider::Provider;
4use crate::core::observability::Observable;
5
6#[derive(Args, Debug)]
7pub struct KeyringArgs {
8    #[command(subcommand)]
9    pub command: KeyringCommands,
10}
11
12#[derive(Subcommand, Debug)]
13pub enum KeyringCommands {
14    /// Add a new email identity, bucket-config, or encryption key
15    Add(AddArgs),
16    /// Edit an existing entry's fields
17    Modify {
18        /// Alias of the entry to edit. Interactively selected from every
19        /// configured entry (of any kind) when omitted.
20        alias: Option<String>,
21    },
22    /// Remove a configured entry and its secret
23    Delete {
24        /// Alias of the entry to remove.
25        alias: String,
26    },
27    /// List every configured entry
28    List,
29}
30
31impl Observable for KeyringCommands {
32    fn command_name(&self) -> &'static str {
33        match self {
34            KeyringCommands::Add(_) => "keyring.add",
35            KeyringCommands::Modify { .. } => "keyring.modify",
36            KeyringCommands::Delete { .. } => "keyring.delete",
37            KeyringCommands::List => "keyring.list",
38        }
39    }
40}
41
42#[derive(Args, Debug)]
43pub struct AddArgs {
44    #[command(subcommand)]
45    pub kind: Option<AddKind>,
46}
47
48#[derive(Subcommand, Debug)]
49pub enum AddKind {
50    /// Authenticate an email identity and register it under a local alias
51    Email {
52        /// Email address of the identity to authenticate, e.g. first.last@example.com
53        email: String,
54
55        /// Local alias to store this identity under (e.g. first-last).
56        /// Defaults to a sanitized form of the email's local part.
57        #[arg(long)]
58        alias: Option<String>,
59
60        /// Email provider. Auto-detected from the email's domain when
61        /// omitted, falling back to an interactive prompt if detection fails.
62        #[arg(long)]
63        provider: Option<Provider>,
64
65        /// IMAP host, e.g. imap.example.com. Required when --provider is
66        /// "custom" (or resolves to it); ignored for known providers, which
67        /// use their own well-known host.
68        #[arg(long)]
69        host: Option<String>,
70
71        /// IMAP port. Defaults to 993 for a custom provider when omitted;
72        /// ignored for known providers, which use their own well-known port.
73        #[arg(long)]
74        port: Option<u16>,
75    },
76
77    /// Interactively configure a new S3-compatible bucket-config
78    Bucket {
79        /// Alias to register this bucket-config under (e.g. "backup").
80        /// Prompted if omitted.
81        alias: Option<String>,
82    },
83
84    /// Register a new symmetric encryption key, generated or imported
85    /// (ADR-0026)
86    EncryptionKey {
87        /// Alias to register this key under (e.g. "primary"). Prompted if
88        /// omitted.
89        alias: Option<String>,
90    },
91}