oscli

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

src/cli.ts
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.

Shell
bun run src/cli.ts
Shell
bun run src/cli.ts --json
  • Normal run: prompts, logs, intro, outro, boxes, progress, and success lines render normally
  • JSON run: only the value from cli.setResult() is printed

Minimal diff

This is the only code you need to add to support JSON mode.

src/cli.ts
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.

On this page