Skip to content

Commit 1763da7

Browse files
committed
Add --help output and test for hygiene checks
Support printing concern-specific help for the split hygiene entrypoints and add a test. - scripts/check-repo-hygiene.mjs: handle `--help`/`-h` early and print a formatted usage message (formatUsage) then exit 0. parseArgs now recognizes help flags. The usage text includes the selected concern name and common options (--root, --changed-files, --diff-file, --only). - scripts/check-repo-concerns.test.mjs: add a test that invokes each entrypoint with `--help` and asserts the process exits successfully and prints usage/help text including the concern-specific name and expected options. This prevents the checks from running when users request help and ensures the help text is descriptive for each concern.
1 parent aa306a6 commit 1763da7

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

scripts/check-repo-concerns.test.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,32 @@ test("repo security entrypoint reports only prompt security failures", () => {
110110
rmSync(root, { recursive: true, force: true });
111111
}
112112
});
113+
114+
test("split check entrypoints print concern-specific help without running checks", () => {
115+
const root = makeFixture();
116+
const expectedNames = {
117+
readme: "README hygiene",
118+
rules: "Rule hygiene",
119+
issues: "Issue template policy",
120+
security: "Repo security",
121+
};
122+
123+
try {
124+
write(root, "README.md", "### Other\n\n- [Missing](./rules/missing.mdc)\n");
125+
write(root, "rules/bad.mdc", "# Missing frontmatter\n");
126+
127+
for (const [concern, entrypoint] of Object.entries(entrypoints)) {
128+
const result = run(entrypoint, root, ["--help"]);
129+
130+
assert.equal(result.status, 0);
131+
assert.match(result.stdout, /Usage:/);
132+
assert.match(result.stdout, new RegExp(`${expectedNames[concern]} check`));
133+
assert.match(result.stdout, /--root/);
134+
assert.match(result.stdout, /--changed-files/);
135+
assert.match(result.stdout, /--diff-file/);
136+
assert.equal(result.stderr, "");
137+
}
138+
} finally {
139+
rmSync(root, { recursive: true, force: true });
140+
}
141+
});

scripts/check-repo-hygiene.mjs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { join, normalize, resolve } from "node:path";
55
import { githubBlobPrefix, githubRawPrefix } from "./repo-config.mjs";
66

77
const args = parseArgs(process.argv.slice(2));
8+
if (args.help) {
9+
console.log(formatUsage(args.only));
10+
process.exit(0);
11+
}
12+
813
const root = resolve(args.root ?? process.cwd());
914
const changedFiles = args.changedFiles
1015
? readLines(resolve(root, args.changedFiles))
@@ -61,7 +66,9 @@ function parseArgs(argv) {
6166
const parsed = {};
6267
for (let i = 0; i < argv.length; i += 1) {
6368
const arg = argv[i];
64-
if (arg === "--root") {
69+
if (arg === "--help" || arg === "-h") {
70+
parsed.help = true;
71+
} else if (arg === "--root") {
6572
parsed.root = argv[++i];
6673
} else if (arg === "--changed-files") {
6774
parsed.changedFiles = argv[++i];
@@ -76,6 +83,24 @@ function parseArgs(argv) {
7683
return parsed;
7784
}
7885

86+
function formatUsage(only) {
87+
const selected = parseConcerns(only);
88+
const checkName = describeConcerns(selected);
89+
90+
return [
91+
`${checkName} check`,
92+
"",
93+
"Usage: node scripts/check-repo-hygiene.mjs [options]",
94+
"",
95+
"Options:",
96+
" --root <path> Repository root to check. Defaults to cwd.",
97+
" --changed-files <file> Newline-delimited changed files, relative to root.",
98+
" --diff-file <file> Unified diff file used for README-only checks.",
99+
" --only <concerns> Comma-separated concerns: readme, rules, issues, security.",
100+
" -h, --help Show this help.",
101+
].join("\n");
102+
}
103+
79104
function parseConcerns(value) {
80105
const validConcerns = new Set(["readme", "rules", "issues", "security"]);
81106
const selected = new Set((value ?? "readme,rules,issues")

0 commit comments

Comments
 (0)