himalaya 2.2.1

CLI to manage emails
//! # m2dir command
//!
//! The `m2dir` command, dispatching onto its subcommands.

use anyhow::Result;
use clap::Subcommand;
use pimalaya_cli::printer::Printer;

use crate::{
    account::context::Account,
    m2dir::{
        client::M2dirClient, create::M2dirMailboxCreateCommand, delete::M2dirMailboxDeleteCommand,
        flag::cli::M2dirFlagCommand, list::M2dirMailboxListCommand,
        message::cli::M2dirMessageCommand,
    },
};

/// M2dir-specific API.
///
/// This command gives you access to the raw m2dir API.
#[derive(Debug, Subcommand)]
#[command(rename_all = "kebab-case")]
pub enum M2dirCommand {
    Create(M2dirMailboxCreateCommand),
    Delete(M2dirMailboxDeleteCommand),
    List(M2dirMailboxListCommand),
    #[command(subcommand)]
    #[command(visible_alias = "msg", aliases = ["messages", "msgs"])]
    Message(M2dirMessageCommand),
    #[command(subcommand)]
    #[command(alias = "flags")]
    Flag(M2dirFlagCommand),
}

impl M2dirCommand {
    /// Runs the subcommand against the account's m2dir store.
    pub fn execute(
        self,
        printer: &mut impl Printer,
        account: &mut Account,
        client: &mut M2dirClient,
    ) -> Result<()> {
        match self {
            Self::Create(cmd) => cmd.execute(printer, client),
            Self::Delete(cmd) => cmd.execute(printer, client),
            Self::List(cmd) => cmd.execute(printer, account, client),

            Self::Message(cmd) => cmd.execute(printer, client),
            Self::Flag(cmd) => cmd.execute(printer, account, client),
        }
    }
}