oscli

Output and logging

Write lines through the shared output system and reuse styles where needed.

oscli routes user-facing output through one output layer so logs, prompts, boxes, progress, and links all stay visually aligned.

Logging

Use cli.log() when you want one line in the normal output flow.

src/cli.ts
await cli.run(async () => {
  cli.log("ready");
  cli.log("warn", "review this before production").bold().underline().flush();
  cli.success("Done.");
});

If you call cli.log(level, message), the returned chain lets you apply text modifiers before the message is written.

Rendered output
  ready
 review this before production
 Done.

Prop

Type

Reusable styles

Use cli.style() when you want to build a style once and reuse it across multiple writes.

src/cli.ts
await cli.run(async () => {
  const callout = cli.style().color("cyan").bold();

  cli.log("info", callout.render("important"));
  cli.log(callout.render("plain line with shared styling"));
});
Rendered output
 important
  plain line with shared styling

Prop

Type

Exit with hints

Use cli.exit() when the command cannot continue and you want a concrete next step in the error output.

src/cli.ts
cli.exit("package.json not found.", {
  hint: "Run this command from the project root.",
  code: "not_found",
});
Rendered output

 package.json not found.
    → Run this command from the project root.

Inline confirm

Use cli.confirm() when you need one simple confirmation in the middle of a flow without defining a named prompt.

src/cli.ts
await cli.run(async () => {
  const approved = await cli.confirm("Deploy now?", false);

  if (!approved) {
    cli.exit("Cancelled.");
  }
});
Rendered output
  Deploy now?
 (y/N) _

cli.exit() writes to stderr. cli.log("error", ...) also writes to stderr. Other output stays on stdout.

On this page