use anyhow::{Result, bail};
use opencode_cloud_core::docker::DockerClient;
use std::io::IsTerminal;
pub async fn verify_docker_available() -> Result<()> {
let client = match DockerClient::new() {
Ok(c) => c,
Err(_) => {
bail!(
"Docker is not available.\n\n\
Make sure Docker is installed and the daemon is running.\n\n\
Linux: sudo systemctl start docker\n\
macOS: Open Docker Desktop\n\
Check: docker ps\n\
Check: ls -l /var/run/docker.sock (Linux default)\n\
Check: your user has access to the Docker socket\n\
Fix: Linux: sudo usermod -aG docker $USER\n\
Note: Restart your session or reboot after installing Docker"
);
}
};
if client.verify_connection().await.is_err() {
bail!(
"Docker is not responding.\n\n\
Start or restart the Docker daemon, then try again.\n\n\
Linux: sudo systemctl start docker\n\
Linux: sudo systemctl restart docker\n\
macOS: Open Docker Desktop\n\
Check: docker ps\n\
Check: ls -l /var/run/docker.sock (Linux default)\n\
Check: your user has access to the Docker socket\n\
Fix: Linux: sudo usermod -aG docker $USER\n\
Note: Restart your session or reboot after installing Docker"
);
}
Ok(())
}
pub fn verify_tty() -> Result<()> {
if !std::io::stdin().is_terminal() {
bail!(
"No TTY detected. Use occ config set or provide config file.\n\n\
For non-interactive setup:\n \
occ setup --bootstrap\n\n\
Then start the service and complete IOTP + passkey onboarding in the web login page.\n\n\
Or edit the config file directly:\n \
~/.config/opencode-cloud/config.json"
);
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_verify_tty_runs() {
let _ = verify_tty();
}
}