himalaya 2.2.1

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

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

use crate::{
    account::context::Account,
    pimdir::{
        client::PimdirClient,
        queue::{cancel::PimdirQueueCancelCommand, list::PimdirQueueListCommand},
    },
};

/// Read and retract the writes Himalaya staged.
///
/// A pimdir store is a replica the sync engine owns, so a write is appended
/// to the store's queue and applied on the engine's next run.
///
/// A staged flag, move or deletion shows in the ordinary listing straight
/// away. A staged creation has no id until the engine applies it, which is
/// what these commands are for.
#[derive(Debug, Subcommand)]
#[command(rename_all = "kebab-case")]
pub enum PimdirQueueCommand {
    #[command(alias = "ls")]
    List(PimdirQueueListCommand),
    Cancel(PimdirQueueCancelCommand),
}

impl PimdirQueueCommand {
    /// Runs the subcommand against the account's pimdir store.
    pub fn execute(
        self,
        printer: &mut impl Printer,
        account: &mut Account,
        client: &mut PimdirClient,
    ) -> Result<()> {
        match self {
            Self::List(cmd) => cmd.execute(printer, account, client),
            Self::Cancel(cmd) => cmd.execute(printer, client),
        }
    }
}