pub mod compose;
pub mod custom;
pub mod devcontainer;
pub mod error;
pub mod null;
pub mod registry;
use async_trait::async_trait;
use std::collections::BTreeMap;
use tokio::process::Child;
pub use error::BackendError;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServiceStatus {
Running,
Stopped,
Missing,
}
#[derive(Debug, Clone, Default)]
pub struct ExecOptions {
pub tty: bool,
pub env: BTreeMap<String, String>,
pub workdir: Option<String>,
}
#[async_trait]
pub trait Backend: Send + Sync {
fn name(&self) -> &'static str;
async fn status(&self, service: &str) -> Result<ServiceStatus, BackendError>;
async fn exec(
&self,
service: &str,
argv: &[&str],
opts: &ExecOptions,
) -> Result<i32, BackendError>;
async fn exec_with_stdin(
&self,
_service: &str,
_argv: &[&str],
_opts: &ExecOptions,
_stdin: &str,
) -> Result<i32, BackendError> {
Err(BackendError::Reported(
"this backend does not support stdin-piped exec".into(),
))
}
async fn spawn_exec(
&self,
_service: &str,
_argv: &[&str],
_opts: &ExecOptions,
) -> Result<Child, BackendError> {
Err(BackendError::Reported(
"this backend does not support sink-aware exec".into(),
))
}
async fn spawn_exec_with_stdin(
&self,
_service: &str,
_argv: &[&str],
_opts: &ExecOptions,
) -> Result<Child, BackendError> {
Err(BackendError::Reported(
"this backend does not support sink-aware stdin-piped exec".into(),
))
}
async fn passthrough(&self, args: &[&str]) -> Result<i32, BackendError>;
async fn tail_logs(&self, _service: &str) -> Result<Child, BackendError> {
Err(BackendError::Reported(
"no container backend configured (set runtime.backend = \"compose\" in croft.toml)"
.into(),
))
}
async fn list_services(&self) -> Result<Vec<String>, BackendError> {
Ok(Vec::new())
}
async fn service_action(
&self,
_action: &str,
_services: &[&str],
) -> Result<Child, BackendError> {
Err(BackendError::Reported(
"no container backend configured (set runtime.backend = \"compose\")".into(),
))
}
}
pub mod service_action {
pub const UP: &str = "up";
pub const DOWN: &str = "down";
pub const STOP: &str = "stop";
pub const RESTART: &str = "restart";
}