use std::{io, process::Command};
use super::ensure_success;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemoveHandle {
id: Option<String>,
}
impl RemoveHandle {
#[must_use]
pub fn new(id: Option<String>) -> Self {
Self { id }
}
#[must_use]
pub fn id(&self) -> Option<&String> {
self.id.as_ref()
}
pub fn remove(&self) -> io::Result<()> {
if let Some(mut cmd) = self.to_command() {
ensure_success(&cmd.output()?)?;
}
Ok(())
}
#[must_use]
pub fn to_command(&self) -> Option<Command> {
let mut cmd = Command::new("termux-notification-remove");
cmd.arg(self.id()?);
Some(cmd)
}
}