Skip to content

Commit 86749c0

Browse files
koki-developclaude
andcommitted
feat: Add --json output option to run command
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 063a7b6 commit 86749c0

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ bun run build
2020

2121
# Type check (no test or lint scripts are configured)
2222
npx tsc --noEmit
23+
24+
# Format check
25+
npx prettier --check .
2326
```
2427

2528
## Build System

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ You can pass multiple files:
3737
$ codize run main.ts utils.ts
3838
```
3939

40+
### JSON Output
41+
42+
Use `--json` to get structured output for programmatic use:
43+
44+
```bash
45+
$ codize run main.ts --json
46+
{
47+
"compile": {
48+
"stdout": "",
49+
"stderr": "",
50+
"output": "",
51+
"exitCode": 0
52+
},
53+
"run": {
54+
"stdout": "Hello\n",
55+
"stderr": "",
56+
"output": "Hello\n",
57+
"exitCode": 0
58+
}
59+
}
60+
```
61+
4062
## License
4163

4264
[MIT](../LICENSE)

src/commands/run.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ export function registerRunCommand(program: Command): void {
5858
"-k, --api-key <key>",
5959
"Codize API key (defaults to CODIZE_API_KEY env var)",
6060
)
61+
.option("--json", "Output result as JSON instead of plain text")
6162
.action(
6263
async (
6364
files: string[],
64-
options: { language?: string; apiKey?: string },
65+
options: { language?: string; apiKey?: string; json?: boolean },
6566
) => {
6667
const apiKey = options.apiKey ?? process.env["CODIZE_API_KEY"];
6768
if (!apiKey) {
@@ -89,11 +90,21 @@ export function registerRunCommand(program: Command): void {
8990
throw err;
9091
}
9192

92-
if (result.data.compile != null && result.data.compile.output !== "") {
93-
process.stderr.write(result.data.compile.output);
93+
if (options.json) {
94+
const indent = process.stdout.isTTY ? 2 : undefined;
95+
process.stdout.write(
96+
JSON.stringify(result.data, null, indent) + "\n",
97+
);
98+
} else {
99+
if (
100+
result.data.compile != null &&
101+
result.data.compile.output !== ""
102+
) {
103+
process.stderr.write(result.data.compile.output);
104+
}
105+
process.stdout.write(result.data.run.output);
94106
}
95107

96-
process.stdout.write(result.data.run.output);
97108
if (result.data.compile != null && result.data.compile.exitCode !== 0) {
98109
process.exitCode = result.data.compile.exitCode ?? 1;
99110
} else {

0 commit comments

Comments
 (0)