Show stderr output in debug mode

This commit is contained in:
Chris Wanstrath 2026-02-24 09:58:45 -08:00
parent 8a654a559b
commit 9ed2b1c192
2 changed files with 25 additions and 3 deletions

View File

@ -1,7 +1,25 @@
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
const DEBUG = !!process.env.DEBUG
export function spinner(text: string, prefix?: string) {
const tag = prefix ? `\x1b[2m[${prefix}]\x1b[22m ` : ""
if (DEBUG) {
process.stderr.write(`${tag}${text}\n`)
return {
set text(t: string) {
process.stderr.write(`${tag}${t}\n`)
},
succeed(msg: string) {
process.stderr.write(`${tag}${msg}\n`)
},
fail(msg: string) {
process.stderr.write(`${tag}${msg}\n`)
},
stop() {},
}
}
let i = 0
const id = setInterval(() => {
process.stderr.write(`\r\x1b[2K${frames[i++ % frames.length]} ${tag}${text}`)

View File

@ -4,6 +4,7 @@ import { dirname, join } from "path"
import { getApiKey } from "./env.ts"
import { info } from "./fmt.ts"
const DEBUG = !!process.env.DEBUG
const CONTAINER_NAME = "sandlot"
const USER = "ubuntu"
const CLAUDE_BIN = `/home/${USER}/.local/bin/claude`
@ -33,7 +34,8 @@ function requireContainer(): void {
/** Run a shell command, logging stderr on failure. */
async function run(cmd: ReturnType<typeof $>, step: string): Promise<void> {
const result = await cmd.nothrow().quiet()
const prepared = DEBUG ? cmd.nothrow() : cmd.nothrow().quiet()
const result = await prepared
if (result.exitCode !== 0) {
const stderr = result.stderr.toString().trim()
const stdout = result.stdout.toString().trim()
@ -60,7 +62,8 @@ async function createContainer(home: string): Promise<void> {
if (mounts.dev) args.push("--mount", `type=bind,source=${home}/dev,target=/host/dev,readonly`)
if (mounts.code) args.push("--mount", `type=bind,source=${home}/code,target=/host/code,readonly`)
args.push("-v", `${home}/.sandlot:/sandlot`, "ubuntu:24.04", "sleep", "infinity")
const result = await $`${args}`.nothrow().quiet()
const prepared = DEBUG ? $`${args}`.nothrow() : $`${args}`.nothrow().quiet()
const result = await prepared
if (result.exitCode !== 0) {
const stderr = result.stderr.toString().trim()
const stdout = result.stdout.toString().trim()
@ -234,7 +237,8 @@ export async function ensure(log?: (msg: string) => void): Promise<void> {
requireContainer()
// Ensure the container daemon is running
await $`container system start`.nothrow().quiet()
if (DEBUG) await $`container system start`.nothrow()
else await $`container system start`.nothrow().quiet()
const s = await status()
if (s === "running") return