info command

This commit is contained in:
Chris Wanstrath 2026-01-29 13:01:50 -08:00
parent 0f5fd50fec
commit 830cd4e45d

View File

@ -37,6 +37,34 @@ async function post<T, B = unknown>(url: string, body?: B): Promise<T | undefine
}
}
async function infoApp(name: string) {
const app: App | undefined = await get(`/api/apps/${name}`)
if (!app) {
console.error(`App not found: ${name}`)
return
}
const icon = STATE_ICONS[app.state] ?? '◯'
console.log(`${icon} ${color.bold(app.name)}`)
console.log(` State: ${app.state}`)
if (app.port) {
console.log(` Port: ${app.port}`)
console.log(` URL: http://localhost:${app.port}`)
}
if (app.started) {
const uptime = Date.now() - app.started
const seconds = Math.floor(uptime / 1000) % 60
const minutes = Math.floor(uptime / 60000) % 60
const hours = Math.floor(uptime / 3600000)
const parts = []
if (hours) parts.push(`${hours}h`)
if (minutes) parts.push(`${minutes}m`)
parts.push(`${seconds}s`)
console.log(` Uptime: ${parts.join(' ')}`)
}
if (app.error) console.log(` Error: ${color.red(app.error)}`)
}
async function listApps() {
const apps: App[] | undefined = await get('/api/apps')
if (!apps) return
@ -130,6 +158,12 @@ program
.name('toes')
.version('0.0.1', '-v, --version')
program
.command('info')
.description('Show info for an app')
.argument('<name>', 'app name')
.action(infoApp)
program
.command('list')
.description('List all apps')