From 6de86bf5ace93bfa9e51e918a177183b1d620688 Mon Sep 17 00:00:00 2001 From: Ajit Panigrahi Date: Mon, 20 May 2024 13:47:21 +0530 Subject: [PATCH] feat: add --version flag for CLI PR-URL: https://github.com/isaacs/rimraf/pull/308 Credit: @ajitzero Close: #308 Reviewed-by: @isaacs --- CHANGELOG.md | 1 + README.md | 3 ++- src/bin.mts | 5 +++++ test/bin.ts | 13 +++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2304bbc..eb80bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 6.0 - Drop support for nodes before v20 +- Add `--version` to CLI # 5.0 diff --git a/README.md b/README.md index 7ab1a5d..13590e2 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ Synchronous form of `rimraf.moveRemove()` ### Command Line Interface ``` -rimraf version 4.3.0 +rimraf version 6.0.1 Usage: rimraf [ ...] Deletes all files and folders at "path", recursively. @@ -186,6 +186,7 @@ Deletes all files and folders at "path", recursively. Options: -- Treat all subsequent arguments as paths -h --help Display this usage info + --version Display version --preserve-root Do not remove '/' recursively (default) --no-preserve-root Do not treat '/' specially -G --no-glob Treat arguments as literal paths, not globs (default) diff --git a/src/bin.mts b/src/bin.mts index db47b66..098d163 100755 --- a/src/bin.mts +++ b/src/bin.mts @@ -20,6 +20,7 @@ Deletes all files and folders at "path", recursively. Options: -- Treat all subsequent arguments as paths -h --help Display this usage info + --version Display version --preserve-root Do not remove '/' recursively (default) --no-preserve-root Do not treat '/' specially -G --no-glob Treat arguments as literal paths, not globs (default) @@ -158,6 +159,9 @@ const main = async (...args: string[]) => { } else if (arg === '-h' || arg === '--help') { console.log(help) return 0 + } else if (arg === '--version') { + console.log(version) + return 0 } else if (arg === '--interactive' || arg === '-i') { interactive = true continue @@ -258,6 +262,7 @@ const main = async (...args: string[]) => { return 0 } main.help = help +main.version = version export default main diff --git a/test/bin.ts b/test/bin.ts index fcfbbe3..665f92c 100644 --- a/test/bin.ts +++ b/test/bin.ts @@ -50,6 +50,19 @@ t.test('basic arg parsing stuff', async t => { CALLS.length = 0 }) + t.test('binary version', t => { + const cases = [['--version'], ['a', 'b', '--version', 'c']] + for (const c of cases) { + t.test(c.join(' '), async t => { + t.equal(await bin(...c), 0) + t.same(LOGS, [[bin.version]]) + t.same(ERRS, []) + t.same(CALLS, []) + }) + } + t.end() + }) + t.test('helpful output', t => { const cases = [['-h'], ['--help'], ['a', 'b', '--help', 'c']] for (const c of cases) {