Skip to content

Commit 7304761

Browse files
dmealingclaude
andcommitted
feat(cli): parsePromptSnapshotArgs for meta prompt-snapshot [FR-004]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 657e6f5 commit 7304761

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

server/typescript/packages/cli/src/lib/args.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,33 @@ export function parseVerifyArgs(argv: string[]): VerifyFlags {
100100
};
101101
}
102102

103+
// ---------------------------------------------------------------------------
104+
// prompt-snapshot flags
105+
// ---------------------------------------------------------------------------
106+
107+
export interface PromptSnapshotFlags {
108+
/** Compare against committed snapshots and fail on drift; never write. */
109+
check: boolean;
110+
/** Directory (relative to cwd) holding provider-resolved template text. */
111+
prompts: string | undefined;
112+
}
113+
114+
export function parsePromptSnapshotArgs(argv: string[]): PromptSnapshotFlags {
115+
const { values } = parseArgs({
116+
args: argv,
117+
options: {
118+
check: { type: "boolean", default: false },
119+
prompts: { type: "string" },
120+
},
121+
strict: true,
122+
allowPositionals: false,
123+
});
124+
return {
125+
check: !!values.check,
126+
prompts: values.prompts,
127+
};
128+
}
129+
103130
// ---------------------------------------------------------------------------
104131
// migrate flags
105132
// ---------------------------------------------------------------------------
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, test, expect } from "bun:test";
2+
import { parsePromptSnapshotArgs } from "../../src/lib/args.js";
3+
4+
describe("parsePromptSnapshotArgs", () => {
5+
test("defaults: check false, prompts undefined", () => {
6+
expect(parsePromptSnapshotArgs([])).toEqual({ check: false, prompts: undefined });
7+
});
8+
test("--check sets check true", () => {
9+
expect(parsePromptSnapshotArgs(["--check"])).toEqual({ check: true, prompts: undefined });
10+
});
11+
test("--prompts <dir> is captured", () => {
12+
expect(parsePromptSnapshotArgs(["--prompts", "templates"])).toEqual({
13+
check: false,
14+
prompts: "templates",
15+
});
16+
});
17+
test("throws on an unknown flag", () => {
18+
expect(() => parsePromptSnapshotArgs(["--bogus"])).toThrow();
19+
});
20+
test("throws on a positional argument", () => {
21+
expect(() => parsePromptSnapshotArgs(["extra"])).toThrow();
22+
});
23+
});

0 commit comments

Comments
 (0)