use std::any::Any;
use std::path::Path;
use anyhow::{Result, anyhow};
use async_trait::async_trait;
pub trait CliContext: Send + Sync {
fn repo_path(&self) -> Option<&Path>;
fn operation_id_wire(&self) -> String;
fn should_output_json(&self, repo_config: Option<&repo::Config>) -> bool;
}
#[async_trait]
pub trait WeftExtensions: Send + Sync {
async fn auth(
&self,
ctx: &(dyn CliContext + 'static),
command: &(dyn Any + Send + Sync),
) -> Result<()>;
async fn support(
&self,
ctx: &(dyn CliContext + 'static),
command: &(dyn Any + Send + Sync),
) -> Result<()>;
async fn presence_publish(
&self,
ctx: &(dyn CliContext + 'static),
session: String,
interval_secs: u64,
) -> Result<()>;
}
pub struct NoopWeftExtensions;
#[async_trait]
impl WeftExtensions for NoopWeftExtensions {
async fn auth(
&self,
_ctx: &(dyn CliContext + 'static),
_command: &(dyn Any + Send + Sync),
) -> Result<()> {
Err(anyhow!(not_enabled_error("auth")))
}
async fn support(
&self,
_ctx: &(dyn CliContext + 'static),
_command: &(dyn Any + Send + Sync),
) -> Result<()> {
Err(anyhow!(not_enabled_error("support")))
}
async fn presence_publish(
&self,
_ctx: &(dyn CliContext + 'static),
_session: String,
_interval_secs: u64,
) -> Result<()> {
Err(anyhow!(not_enabled_error("presence publish")))
}
}
fn not_enabled_error(command: &str) -> String {
format!(
"`heddle {command}` requires the client build of Heddle. \
Install it from https://heddleco.com or rebuild the CLI with \
`--features client` if you're working from source."
)
}