use async_trait::async_trait;
use thiserror::Error;
use crate::job::AssetSender;
#[async_trait]
pub trait Prompter: Send + Sync {
async fn prompt(&self, message: &str) -> Result<String, PromptError>;
fn set_asset_sender(&mut self, sender: Option<AssetSender>) -> Result<(), PromptError> {
if sender.is_none() {
return Ok(());
} else {
Err(PromptError::FeatureNotSupported(
"attaching assets".to_string(),
))
}
}
}
#[derive(Debug, Error)]
pub enum PromptError {
#[error("Prompt was canceled by the user.")]
Canceled,
#[error("Prompt input failed due to IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Prompt failed to execute to completion: {0}")]
Async(#[from] tokio::task::JoinError),
#[error("Prompter does not support {0}")]
FeatureNotSupported(String),
}