opencode_cloud/wizard/
prechecks.rs1use anyhow::{Result, bail};
6use opencode_cloud_core::docker::DockerClient;
7use std::io::IsTerminal;
8
9pub async fn verify_docker_available() -> Result<()> {
14 let client = match DockerClient::new() {
15 Ok(c) => c,
16 Err(_) => {
17 bail!(
18 "Docker is not available.\n\n\
19 Make sure Docker is installed and the daemon is running.\n\n\
20 Linux: sudo systemctl start docker\n\
21 macOS: Open Docker Desktop\n\
22 Check: docker ps\n\
23 Check: ls -l /var/run/docker.sock (Linux default)\n\
24 Check: your user has access to the Docker socket\n\
25 Fix: Linux: sudo usermod -aG docker $USER"
26 );
27 }
28 };
29
30 if client.verify_connection().await.is_err() {
31 bail!(
32 "Docker is not responding.\n\n\
33 Start or restart the Docker daemon, then try again.\n\n\
34 Linux: sudo systemctl start docker\n\
35 Linux: sudo systemctl restart docker\n\
36 macOS: Open Docker Desktop\n\
37 Check: docker ps\n\
38 Check: ls -l /var/run/docker.sock (Linux default)\n\
39 Check: your user has access to the Docker socket\n\
40 Fix: Linux: sudo usermod -aG docker $USER"
41 );
42 }
43
44 Ok(())
45}
46
47pub fn verify_tty() -> Result<()> {
51 if !std::io::stdin().is_terminal() {
52 bail!(
53 "No TTY detected. Use occ config set or provide config file.\n\n\
54 For non-interactive setup, pre-set auth credentials then run commands:\n \
55 occ config set username <user>\n \
56 occ config set password # will prompt\n\n\
57 Or edit the config file directly:\n \
58 ~/.config/opencode-cloud/config.json"
59 );
60 }
61 Ok(())
62}
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
72 fn test_verify_tty_runs() {
73 let _ = verify_tty();
76 }
77}