Skip to content

Commit d090efa

Browse files
committed
feat: add --help flag to install/uninstall scripts
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 9034fd7 commit d090efa

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

postinstall.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ const flags = parseCliFlags(process.argv)
2929
const DRY_RUN = flags.dryRun
3030
const VERBOSE = flags.verbose
3131

32+
/** Print usage information and exit */
33+
if (flags.help) {
34+
console.log(`Usage: node postinstall.mjs [options]
35+
36+
Install OpenCoder agents to ~/.config/opencode/agents/
37+
38+
Options:
39+
--dry-run Simulate installation without copying files
40+
--verbose Enable verbose output for debugging
41+
--help Show this help message and exit
42+
43+
Examples:
44+
node postinstall.mjs # Install agents
45+
node postinstall.mjs --dry-run # Preview what would be installed
46+
node postinstall.mjs --verbose # Install with detailed logging`)
47+
process.exit(0)
48+
}
49+
3250
/** Create logger with verbose flag */
3351
const logger = createLogger(VERBOSE)
3452
const verbose = logger.verbose

preuninstall.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ const flags = parseCliFlags(process.argv)
2828
const DRY_RUN = flags.dryRun
2929
const VERBOSE = flags.verbose
3030

31+
/** Print usage information and exit */
32+
if (flags.help) {
33+
console.log(`Usage: node preuninstall.mjs [options]
34+
35+
Remove OpenCoder agents from ~/.config/opencode/agents/
36+
37+
Options:
38+
--dry-run Simulate removal without deleting files
39+
--verbose Enable verbose output for debugging
40+
--help Show this help message and exit
41+
42+
Examples:
43+
node preuninstall.mjs # Remove agents
44+
node preuninstall.mjs --dry-run # Preview what would be removed
45+
node preuninstall.mjs --verbose # Remove with detailed logging`)
46+
process.exit(0)
47+
}
48+
3149
/** Create logger with verbose flag */
3250
const logger = createLogger(VERBOSE)
3351
const verbose = logger.verbose

tests/install.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,58 @@ Adding more text to ensure minimum length requirement is satisfied here.`
11281128
// Should show validation passed for each file
11291129
expect(stdout).toContain("Validation passed")
11301130
})
1131+
1132+
it("should run actual postinstall.mjs with --help", async () => {
1133+
const proc = Bun.spawn(["node", "postinstall.mjs", "--help"], {
1134+
cwd: process.cwd(),
1135+
stdout: "pipe",
1136+
stderr: "pipe",
1137+
})
1138+
1139+
const exitCode = await proc.exited
1140+
const stdout = await new Response(proc.stdout).text()
1141+
const stderr = await new Response(proc.stderr).text()
1142+
1143+
// Should exit with code 0
1144+
expect(exitCode).toBe(0)
1145+
1146+
// Should show usage information
1147+
expect(stdout).toContain("Usage:")
1148+
expect(stdout).toContain("postinstall.mjs")
1149+
expect(stdout).toContain("Options:")
1150+
expect(stdout).toContain("--dry-run")
1151+
expect(stdout).toContain("--verbose")
1152+
expect(stdout).toContain("--help")
1153+
1154+
// Should not have errors
1155+
expect(stderr).toBe("")
1156+
})
1157+
1158+
it("should run actual preuninstall.mjs with --help", async () => {
1159+
const proc = Bun.spawn(["node", "preuninstall.mjs", "--help"], {
1160+
cwd: process.cwd(),
1161+
stdout: "pipe",
1162+
stderr: "pipe",
1163+
})
1164+
1165+
const exitCode = await proc.exited
1166+
const stdout = await new Response(proc.stdout).text()
1167+
const stderr = await new Response(proc.stderr).text()
1168+
1169+
// Should exit with code 0
1170+
expect(exitCode).toBe(0)
1171+
1172+
// Should show usage information
1173+
expect(stdout).toContain("Usage:")
1174+
expect(stdout).toContain("preuninstall.mjs")
1175+
expect(stdout).toContain("Options:")
1176+
expect(stdout).toContain("--dry-run")
1177+
expect(stdout).toContain("--verbose")
1178+
expect(stdout).toContain("--help")
1179+
1180+
// Should not have errors
1181+
expect(stderr).toBe("")
1182+
})
11311183
})
11321184

11331185
describe("full install/uninstall cycle", () => {

0 commit comments

Comments
 (0)