Doctor Command
A doctor command (in the style of brew doctor or node --check) iterates
over a list of environment preconditions, reports the status of each one, and
exits with code 1 as soon as it detects a failure. It is the ideal entry point
for new contributors and for CI smoke tests.
The pattern combines process.* and env.* in a sequence of sequential checks.
Each check prints [OK], [!] (non-fatal warning), or [X] (failure), and a
boolean variable ok accumulates the overall state:
Checks OS, architecture, PID, uptime, memory usage, working directory, HOME,
and an optional environment variable. Exits with process.exit(0) if everything
is OK or process.exit(1) if any required check fails.
// Feature: doctor / diagnostics — self-check script
// Syntax: combines `process.*` + `env.*` + custom checks. Prints
// a readable status and exits with a non-zero code if anything fails.
// When to use: a `myapp doctor` command for new users; CI smoke tests.
use std::process
use std::env
print("=== Zolo doctor ===\n")
var ok = true
// 1. Platform
print("OS: {env.os()}")
print("ARCH: {env.arch()}")
// 2. PID, uptime, memory.
print("PID: {process.pid()}")
print("Uptime: {process.uptime()}s")
let mem = process.memory_usage()
print("Memory: rss={mem.rss} bytes")
// 3. Working directory — must be readable.
let cwd, err = process.cwd()
if cwd == nil {
print("[X] cwd unavailable: {err}")
ok = false
} else {
print("[OK] cwd: {cwd}")
}
// 4. HOME defined.
let home = env.home_dir()
if home == nil {
print("[X] HOME not detected")
ok = false
} else {
print("[OK] HOME: {home}")
}
// 5. Required environment variable?
let demo = env.get("ZOLO_DOCTOR_REQUIRED")
if demo == nil {
// Warning, not failure (tweak to your app).
print("[!] ZOLO_DOCTOR_REQUIRED not set (optional)")
} else {
print("[OK] ZOLO_DOCTOR_REQUIRED = {demo}")
}
print("")
if ok {
print("status: OK")
process.exit(0)
} else {
print("status: FAILED")
process.exit(1)
}
// expected (healthy):
// ...checks...
// status: OK
Requires the Zolo CLI/host — open in the playground or run locally.
Challenge
Add a check that reads env.get("DATABASE_URL") and treats its absence as a
failure (not just a warning). Observe how that changes the exit code.