JSON mode
Suppress decorative output and return a single machine-readable result.
JSON mode is for scripts and integrations. Turn it on in createCLI(), then
store one final value with cli.setResult().
Enable JSON mode
import { createCLI } from "@oscli-dev/oscli";
export const cli = createCLI((b) => ({
description: "json demo",
json: true,
prompts: {
name: b.text().label("Name").default("my-app"),
},
}));
await cli.run(async () => {
await cli.prompt.name();
cli.setResult({ name: cli.storage.name, created: true });
});What changes under --json
Use --json only when you want raw output for another process.
bun run src/cli.tsbun run src/cli.ts --jsonNormal run: prompts, logs, intro, outro, boxes, progress, and success lines render normallyJSON run: only the value fromcli.setResult()is printed
Minimal diff
This is the only code you need to add to support JSON mode.
export const cli = createCLI((b) => ({
description: "json demo",
prompts: {
name: b.text().label("Name"),
},
json: true,
}));
await cli.run(async () => {
await cli.prompt.name();
cli.setResult({ name: cli.storage.name });
});Reference
Prop
Type
When --json is active, oscli suppresses decorative output. That includes
prompt summary lines, intro and outro lines, logs, boxes, spinners, and
progress output.