-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
101 lines (92 loc) · 2.57 KB
/
Copy pathcli.ts
File metadata and controls
101 lines (92 loc) · 2.57 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
export interface CliOptions {
questionnaireIds: string[];
modelIds: string[];
runId?: string;
listQuestionnaires: boolean;
listModels: boolean;
help: boolean;
}
function addCommaSeparatedValues(target: string[], rawValue: string): void {
for (const value of rawValue.split(",").map((item) => item.trim())) {
if (value) target.push(value);
}
}
export function parseCliArgs(argv: readonly string[]): CliOptions {
const questionnaireIds: string[] = [];
const modelIds: string[] = [];
let runId: string | undefined;
let listQuestionnaires = false;
let listModels = false;
let help = false;
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === undefined) continue;
const [flag, inlineValue] = arg.split("=", 2);
const consumeValue = (): string => {
if (inlineValue !== undefined) return inlineValue;
const nextValue = argv[index + 1];
if (!nextValue || nextValue.startsWith("-")) {
throw new Error(`Missing value for ${flag}`);
}
index += 1;
return nextValue;
};
switch (flag) {
case "-h":
case "--help":
help = true;
break;
case "--list-questionnaires":
listQuestionnaires = true;
break;
case "--list-models":
listModels = true;
break;
case "-q":
case "--questionnaire":
case "--questionnaires":
addCommaSeparatedValues(questionnaireIds, consumeValue());
break;
case "-m":
case "--model":
case "--models":
addCommaSeparatedValues(modelIds, consumeValue());
break;
case "--run-id":
runId = consumeValue();
break;
default:
throw new Error(`Unknown argument: ${arg}`);
}
}
return {
questionnaireIds,
modelIds,
runId,
listQuestionnaires,
listModels,
help,
};
}
export function formatCliHelp(): string {
return [
"LLM Political Spectrum CLI",
"",
"Run questionnaire prompts against selected LLMs.",
"",
"Usage:",
" bun src/index.ts [options]",
"",
"Options:",
" -q, --questionnaire <id> Questionnaire id to run (repeatable, comma-separated)",
" -m, --model <id> Model id to run (repeatable, comma-separated)",
" Any model string accepted by the ai package can be used",
" --run-id <id> Output run id used in JSONL filenames",
" --list-questionnaires Print available questionnaire ids",
" --list-models Print available model ids",
" -h, --help Show this help text",
"",
"Example:",
" bun src/index.ts --questionnaire political-compass-org --model openai/gpt-5.3-chat --run-id 2026-05-01",
].join("\n");
}