-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
48 lines (40 loc) · 1.29 KB
/
Copy pathcli.js
File metadata and controls
48 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
import { readFile } from "node:fs/promises";
import { analyzeEvidence, renderMarkdown } from "./engine.js";
function usage() {
return "Usage: npm run analyze -- <evidence.json> [--format json|markdown]";
}
function parseArguments(argv) {
const args = [...argv];
const file = args.shift();
let format = "json";
while (args.length > 0) {
const argument = args.shift();
if (argument === "--format") {
format = args.shift();
} else if (argument.startsWith("--format=")) {
format = argument.slice("--format=".length);
} else {
throw new Error(`Unknown argument: ${argument}`);
}
}
if (!file) {
throw new Error(usage());
}
if (!["json", "markdown"].includes(format)) {
throw new Error("--format must be json or markdown");
}
return { file, format };
}
async function main() {
const { file, format } = parseArguments(process.argv.slice(2));
const raw = await readFile(file, "utf8");
const input = JSON.parse(raw);
const result = analyzeEvidence(input);
const output = format === "markdown" ? renderMarkdown(result) : JSON.stringify(result, null, 2);
process.stdout.write(`${output.trimEnd()}\n`);
}
main().catch((error) => {
process.stderr.write(`Token Risk Brief failed: ${error.message}\n`);
process.exitCode = 1;
});