Skip to content

Commit 67fad0b

Browse files
committed
Plumb --regex-hint into replay command; remove duplicate warn guidance
1 parent c6fcdba commit 67fad0b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

github-code-search.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,8 @@ async function searchAction(
287287
process.exit(1);
288288
}
289289
if (warn && !opts.regexHint) {
290-
console.error(
291-
pc.yellow(`⚠ Regex mode — ${warn}\n Provide a manual hint with --regex-hint <term>.`),
292-
);
290+
// warn already contains the --regex-hint guidance; print it as-is.
291+
console.error(pc.yellow(`⚠ Regex mode — ${warn}`));
293292
process.exit(1);
294293
}
295294
effectiveQuery = opts.regexHint ?? apiQuery;
@@ -329,6 +328,7 @@ async function searchAction(
329328
buildOutput(groups, query, org, excludedRepos, excludedExtractRefs, format, outputType, {
330329
includeArchived,
331330
groupByTeamPrefix: opts.groupByTeamPrefix,
331+
regexHint: opts.regexHint,
332332
}),
333333
);
334334
// Check for a newer version and notify on stderr so it never pollutes piped output.

src/output.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ describe("buildReplayCommand", () => {
182182
const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts);
183183
expect(cmd).not.toContain("--group-by-team-prefix");
184184
});
185+
186+
it("includes --regex-hint when regexHint is set", () => {
187+
const groups = [makeGroup("myorg/repoA", ["a.ts"])];
188+
const opts: ReplayOptions = { regexHint: '"axios"' };
189+
const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts);
190+
expect(cmd).toContain("--regex-hint");
191+
expect(cmd).toContain("axios");
192+
});
193+
194+
it("does not include --regex-hint when regexHint is not set (default)", () => {
195+
const groups = [makeGroup("myorg/repoA", ["a.ts"])];
196+
const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set());
197+
expect(cmd).not.toContain("--regex-hint");
198+
});
185199
});
186200

187201
describe("buildReplayDetails", () => {

src/output.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export interface ReplayOptions {
2626
outputType?: OutputType;
2727
includeArchived?: boolean;
2828
groupByTeamPrefix?: string;
29+
/** When set, appends `--regex-hint <term>` to the replay command so the
30+
* result set from a regex query can be reproduced exactly. */
31+
regexHint?: string;
2932
}
3033

3134
// ─── Replay command ───────────────────────────────────────────────────────────
@@ -39,7 +42,7 @@ export function buildReplayCommand(
3942
// Fix: forward all input options so the replay command is fully reproducible — see issue #11
4043
options: ReplayOptions = {},
4144
): string {
42-
const { format, outputType, includeArchived, groupByTeamPrefix } = options;
45+
const { format, outputType, includeArchived, groupByTeamPrefix, regexHint } = options;
4346
const parts: string[] = [
4447
`github-code-search ${JSON.stringify(query)} --org ${org} --no-interactive`,
4548
];
@@ -85,6 +88,9 @@ export function buildReplayCommand(
8588
if (groupByTeamPrefix) {
8689
parts.push(`--group-by-team-prefix ${groupByTeamPrefix}`);
8790
}
91+
if (regexHint) {
92+
parts.push(`--regex-hint ${JSON.stringify(regexHint)}`);
93+
}
8894

8995
return `# Replay:\n${parts.join(" \\\n ")}`;
9096
}
@@ -253,7 +259,7 @@ export function buildOutput(
253259
excludedExtractRefs: Set<string>,
254260
format: OutputFormat,
255261
outputType: OutputType = "repo-and-matches",
256-
extraOptions: Pick<ReplayOptions, "includeArchived" | "groupByTeamPrefix"> = {},
262+
extraOptions: Pick<ReplayOptions, "includeArchived" | "groupByTeamPrefix" | "regexHint"> = {},
257263
): string {
258264
const options: ReplayOptions = { format, outputType, ...extraOptions };
259265
if (format === "json") {

0 commit comments

Comments
 (0)