diff --git a/README.md b/README.md index bbca3ed..8d9d2e2 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ mkdir -p ~/nose/{bin,www} bun dev +## Commands + +Commands can return one of two types: + +- string +- { status: "ok" | "error", output: string } + ## Fonts Use this to examine what's inside the C64 .woff2 font file in public/vendor: diff --git a/nose/bin/load.ts b/nose/bin/load.ts index 5ef2eb6..f49c9ff 100644 --- a/nose/bin/load.ts +++ b/nose/bin/load.ts @@ -8,5 +8,5 @@ export default function (project: string) { state.project = project } - return state?.project ? `loaded ${project}` : `failed to load ${project}` + return state?.project ? `loaded ${project}` : { status: "error", output: `failed to load ${project}` } } \ No newline at end of file diff --git a/nose/bin/ls.ts b/nose/bin/ls.ts index e5cf97a..dc599a9 100644 --- a/nose/bin/ls.ts +++ b/nose/bin/ls.ts @@ -1,17 +1,17 @@ import { readdirSync } from "fs" -import { NOSE_DIR, NOSE_WWW } from "@/config" +import { NOSE_WWW } from "@/config" import { Thread } from "@/shell" import { appPath } from "@/webapp" export default function () { const state = Thread.getStore() - if (!state) return "error: no state" + if (!state) return { status: "error", output: "no state" } const project = state.project - if (!project) return "no project loaded" + if (!project) return { status: "error", output: "no project loaded" } const root = appPath(project) - if (!root) return "error loading project" + if (!root) return { status: "error", output: "error loading project" } let files: string[] = [] diff --git a/src/shell.ts b/src/shell.ts index 9a0c460..afc4843 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -53,7 +53,15 @@ async function exec(cmd: string, args: string[]): Promise<["ok" | "error", strin return ["error", `${cmd} has no default export`] } - return ["ok", await module.default(...args)] + const output = await module.default(...args) + + if (typeof output === "string") { + return ["ok", output] + } else if (typeof output === "object") { + return [output.status || "ok", output.output] + } else { + return ["ok", String(output)] + } } function commandPath(cmd: string): string | undefined {