Skip to main content

pigeon/commands/keyring/
cli.rs

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