Skip to content

Commit

Permalink
feat: add --version flag for CLI
Browse files Browse the repository at this point in the history
PR-URL: #308
Credit: @ajitzero
Close: #308
Reviewed-by: @isaacs
  • Loading branch information
ajitzero authored and isaacs committed Jul 10, 2024
1 parent 49e1923 commit 6de86bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 6.0

- Drop support for nodes before v20
- Add `--version` to CLI

# 5.0

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,15 @@ Synchronous form of `rimraf.moveRemove()`
### Command Line Interface

```
rimraf version 4.3.0
rimraf version 6.0.1
Usage: rimraf <path> [<path> ...]
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)
Expand Down
5 changes: 5 additions & 0 deletions src/bin.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -258,6 +262,7 @@ const main = async (...args: string[]) => {
return 0
}
main.help = help
main.version = version

export default main

Expand Down
13 changes: 13 additions & 0 deletions test/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6de86bf

Please sign in to comment.