Show stderr output in debug mode
This commit is contained in:
parent
8a654a559b
commit
9ed2b1c192
|
|
@ -1,7 +1,25 @@
|
||||||
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
||||||
|
const DEBUG = !!process.env.DEBUG
|
||||||
|
|
||||||
export function spinner(text: string, prefix?: string) {
|
export function spinner(text: string, prefix?: string) {
|
||||||
const tag = prefix ? `\x1b[2m[${prefix}]\x1b[22m ` : ""
|
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
|
let i = 0
|
||||||
const id = setInterval(() => {
|
const id = setInterval(() => {
|
||||||
process.stderr.write(`\r\x1b[2K${frames[i++ % frames.length]} ${tag}${text}`)
|
process.stderr.write(`\r\x1b[2K${frames[i++ % frames.length]} ${tag}${text}`)
|
||||||
|
|
|
||||||
10
src/vm.ts
10
src/vm.ts
|
|
@ -4,6 +4,7 @@ import { dirname, join } from "path"
|
||||||
import { getApiKey } from "./env.ts"
|
import { getApiKey } from "./env.ts"
|
||||||
import { info } from "./fmt.ts"
|
import { info } from "./fmt.ts"
|
||||||
|
|
||||||
|
const DEBUG = !!process.env.DEBUG
|
||||||
const CONTAINER_NAME = "sandlot"
|
const CONTAINER_NAME = "sandlot"
|
||||||
const USER = "ubuntu"
|
const USER = "ubuntu"
|
||||||
const CLAUDE_BIN = `/home/${USER}/.local/bin/claude`
|
const CLAUDE_BIN = `/home/${USER}/.local/bin/claude`
|
||||||
|
|
@ -33,7 +34,8 @@ function requireContainer(): void {
|
||||||
|
|
||||||
/** Run a shell command, logging stderr on failure. */
|
/** Run a shell command, logging stderr on failure. */
|
||||||
async function run(cmd: ReturnType<typeof $>, step: string): Promise<void> {
|
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) {
|
if (result.exitCode !== 0) {
|
||||||
const stderr = result.stderr.toString().trim()
|
const stderr = result.stderr.toString().trim()
|
||||||
const stdout = result.stdout.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.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`)
|
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")
|
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) {
|
if (result.exitCode !== 0) {
|
||||||
const stderr = result.stderr.toString().trim()
|
const stderr = result.stderr.toString().trim()
|
||||||
const stdout = result.stdout.toString().trim()
|
const stdout = result.stdout.toString().trim()
|
||||||
|
|
@ -234,7 +237,8 @@ export async function ensure(log?: (msg: string) => void): Promise<void> {
|
||||||
requireContainer()
|
requireContainer()
|
||||||
|
|
||||||
// Ensure the container daemon is running
|
// 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()
|
const s = await status()
|
||||||
if (s === "running") return
|
if (s === "running") return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user