use anyhow::{Result, bail};
use clap::Parser;
use io_managesieve::client::ManagesieveClient as _;
use pimalaya_cli::printer::{Message, Printer};
use crate::{shared::raw::RawCommandArg, sieve::client::SieveClient};
#[derive(Debug, Parser)]
pub struct SieveRawCommand {
#[command(flatten)]
pub command: RawCommandArg,
}
impl SieveRawCommand {
pub fn execute(self, printer: &mut impl Printer, client: &mut SieveClient) -> Result<()> {
let command = self.command.parse()?;
let command = command.trim_end_matches(['\r', '\n']);
if command.contains('\n') {
bail!("ManageSieve raw accepts a single command line; batching is not supported");
}
let response = client.raw(command.into())?;
printer.out(Message::new(response.to_string()))
}
}