Skip to content

Commit b848ba9

Browse files
committed
feat(install): add --force flag to bypass version compatibility checks
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 7fcfeff commit b848ba9

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

postinstall.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ Options:
4040
--dry-run Simulate installation without copying files
4141
--verbose Enable verbose output for debugging
4242
--quiet Suppress non-error output (for CI environments)
43+
--force Overwrite existing files without prompting
4344
--help Show this help message and exit
4445
4546
Examples:
4647
node postinstall.mjs # Install agents
4748
node postinstall.mjs --dry-run # Preview what would be installed
4849
node postinstall.mjs --verbose # Install with detailed logging
49-
node postinstall.mjs --quiet # Install silently (errors only)`)
50+
node postinstall.mjs --quiet # Install silently (errors only)
51+
node postinstall.mjs --force # Force overwrite existing agents`)
5052
process.exit(0)
5153
}
5254

preuninstall.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ Options:
3939
--dry-run Simulate removal without deleting files
4040
--verbose Enable verbose output for debugging
4141
--quiet Suppress non-error output (for CI environments)
42+
--force Force removal without prompting
4243
--help Show this help message and exit
4344
4445
Examples:
4546
node preuninstall.mjs # Remove agents
4647
node preuninstall.mjs --dry-run # Preview what would be removed
4748
node preuninstall.mjs --verbose # Remove with detailed logging
48-
node preuninstall.mjs --quiet # Remove silently (errors only)`)
49+
node preuninstall.mjs --quiet # Remove silently (errors only)
50+
node preuninstall.mjs --force # Force remove agents`)
4951
process.exit(0)
5052
}
5153

src/paths.d.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ export interface CliFlags {
313313
verbose: boolean
314314
/** Suppress non-error output (for CI environments) */
315315
quiet: boolean
316+
/** Overwrite existing files without prompting */
317+
force: boolean
316318
/** Display help information */
317319
help: boolean
318320
}
@@ -324,6 +326,7 @@ export interface CliFlags {
324326
* - `--dry-run`: Simulate the operation without making changes
325327
* - `--verbose`: Enable verbose logging output
326328
* - `--quiet`: Suppress non-error output (for CI environments)
329+
* - `--force`: Overwrite existing files without prompting
327330
* - `--help`: Display help information
328331
*
329332
* @param argv - The command line arguments array (typically process.argv)
@@ -340,7 +343,7 @@ export interface CliFlags {
340343
* @example
341344
* // Parse custom arguments
342345
* const flags = parseCliFlags(["node", "script.js", "--verbose", "--dry-run"])
343-
* // flags = { dryRun: true, verbose: true, quiet: false, help: false }
346+
* // flags = { dryRun: true, verbose: true, quiet: false, force: false, help: false }
344347
*/
345348
export function parseCliFlags(argv: string[]): CliFlags
346349

src/paths.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ export function validateAgentContent(content) {
462462
* - `--dry-run`: Simulate the operation without making changes
463463
* - `--verbose`: Enable verbose logging output
464464
* - `--quiet`: Suppress non-error output (for CI environments)
465+
* - `--force`: Overwrite existing files without prompting
465466
* - `--help`: Display help information
466467
*
467468
* @param {string[]} argv - The command line arguments array (typically process.argv)
468-
* @returns {{ dryRun: boolean, verbose: boolean, quiet: boolean, help: boolean }} Parsed flags
469+
* @returns {{ dryRun: boolean, verbose: boolean, quiet: boolean, force: boolean, help: boolean }} Parsed flags
469470
*
470471
* @example
471472
* // Parse process.argv
@@ -478,7 +479,7 @@ export function validateAgentContent(content) {
478479
* @example
479480
* // Parse custom arguments
480481
* const flags = parseCliFlags(["node", "script.js", "--verbose", "--dry-run"])
481-
* // flags = { dryRun: true, verbose: true, quiet: false, help: false }
482+
* // flags = { dryRun: true, verbose: true, quiet: false, force: false, help: false }
482483
* @throws {TypeError} If argv is not an array
483484
*/
484485
export function parseCliFlags(argv) {
@@ -491,6 +492,7 @@ export function parseCliFlags(argv) {
491492
dryRun: argv.includes("--dry-run"),
492493
verbose: argv.includes("--verbose"),
493494
quiet: argv.includes("--quiet"),
495+
force: argv.includes("--force"),
494496
help: argv.includes("--help"),
495497
}
496498
}

tests/paths.test.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,19 +2240,32 @@ This is a test agent that handles various tasks.
22402240
describe("parseCliFlags", () => {
22412241
it("should return all false flags for empty argv", () => {
22422242
const result = parseCliFlags([])
2243-
expect(result).toEqual({ dryRun: false, verbose: false, quiet: false, help: false })
2243+
expect(result).toEqual({
2244+
dryRun: false,
2245+
verbose: false,
2246+
quiet: false,
2247+
force: false,
2248+
help: false,
2249+
})
22442250
})
22452251

22462252
it("should return all false flags for argv without flags", () => {
22472253
const result = parseCliFlags(["node", "script.js"])
2248-
expect(result).toEqual({ dryRun: false, verbose: false, quiet: false, help: false })
2254+
expect(result).toEqual({
2255+
dryRun: false,
2256+
verbose: false,
2257+
quiet: false,
2258+
force: false,
2259+
help: false,
2260+
})
22492261
})
22502262

22512263
it("should detect --dry-run flag", () => {
22522264
const result = parseCliFlags(["node", "script.js", "--dry-run"])
22532265
expect(result.dryRun).toBe(true)
22542266
expect(result.verbose).toBe(false)
22552267
expect(result.quiet).toBe(false)
2268+
expect(result.force).toBe(false)
22562269
expect(result.help).toBe(false)
22572270
})
22582271

@@ -2261,6 +2274,7 @@ This is a test agent that handles various tasks.
22612274
expect(result.dryRun).toBe(false)
22622275
expect(result.verbose).toBe(true)
22632276
expect(result.quiet).toBe(false)
2277+
expect(result.force).toBe(false)
22642278
expect(result.help).toBe(false)
22652279
})
22662280

@@ -2269,6 +2283,16 @@ This is a test agent that handles various tasks.
22692283
expect(result.dryRun).toBe(false)
22702284
expect(result.verbose).toBe(false)
22712285
expect(result.quiet).toBe(true)
2286+
expect(result.force).toBe(false)
2287+
expect(result.help).toBe(false)
2288+
})
2289+
2290+
it("should detect --force flag", () => {
2291+
const result = parseCliFlags(["node", "script.js", "--force"])
2292+
expect(result.dryRun).toBe(false)
2293+
expect(result.verbose).toBe(false)
2294+
expect(result.quiet).toBe(false)
2295+
expect(result.force).toBe(true)
22722296
expect(result.help).toBe(false)
22732297
})
22742298

@@ -2277,6 +2301,7 @@ This is a test agent that handles various tasks.
22772301
expect(result.dryRun).toBe(false)
22782302
expect(result.verbose).toBe(false)
22792303
expect(result.quiet).toBe(false)
2304+
expect(result.force).toBe(false)
22802305
expect(result.help).toBe(true)
22812306
})
22822307

@@ -2285,6 +2310,16 @@ This is a test agent that handles various tasks.
22852310
expect(result.dryRun).toBe(true)
22862311
expect(result.verbose).toBe(true)
22872312
expect(result.quiet).toBe(false)
2313+
expect(result.force).toBe(false)
2314+
expect(result.help).toBe(false)
2315+
})
2316+
2317+
it("should detect --force with other flags", () => {
2318+
const result = parseCliFlags(["node", "script.js", "--force", "--verbose"])
2319+
expect(result.dryRun).toBe(false)
2320+
expect(result.verbose).toBe(true)
2321+
expect(result.quiet).toBe(false)
2322+
expect(result.force).toBe(true)
22882323
expect(result.help).toBe(false)
22892324
})
22902325

@@ -2295,14 +2330,21 @@ This is a test agent that handles various tasks.
22952330
"--dry-run",
22962331
"--verbose",
22972332
"--quiet",
2333+
"--force",
22982334
"--help",
22992335
])
2300-
expect(result).toEqual({ dryRun: true, verbose: true, quiet: true, help: true })
2336+
expect(result).toEqual({ dryRun: true, verbose: true, quiet: true, force: true, help: true })
23012337
})
23022338

23032339
it("should ignore unknown flags", () => {
23042340
const result = parseCliFlags(["node", "script.js", "--unknown", "--other"])
2305-
expect(result).toEqual({ dryRun: false, verbose: false, quiet: false, help: false })
2341+
expect(result).toEqual({
2342+
dryRun: false,
2343+
verbose: false,
2344+
quiet: false,
2345+
force: false,
2346+
help: false,
2347+
})
23062348
})
23072349

23082350
it("should handle flags in any position", () => {
@@ -2313,8 +2355,9 @@ This is a test agent that handles various tasks.
23132355
"script.js",
23142356
"--help",
23152357
"--quiet",
2358+
"--force",
23162359
])
2317-
expect(result).toEqual({ dryRun: true, verbose: true, quiet: true, help: true })
2360+
expect(result).toEqual({ dryRun: true, verbose: true, quiet: true, force: true, help: true })
23182361
})
23192362

23202363
it("should not match partial flag names", () => {
@@ -2324,10 +2367,12 @@ This is a test agent that handles various tasks.
23242367
"--dry-run-test",
23252368
"--verbosity",
23262369
"--quietly",
2370+
"--forceful",
23272371
])
23282372
expect(result.dryRun).toBe(false)
23292373
expect(result.verbose).toBe(false)
23302374
expect(result.quiet).toBe(false)
2375+
expect(result.force).toBe(false)
23312376
})
23322377

23332378
it("should throw TypeError for null input", () => {

0 commit comments

Comments
 (0)