Skip to content

Commit 6de86bf

Browse files
ajitzeroisaacs
authored andcommitted
feat: add --version flag for CLI
PR-URL: #308 Credit: @ajitzero Close: #308 Reviewed-by: @isaacs
1 parent 49e1923 commit 6de86bf

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 6.0
22

33
- Drop support for nodes before v20
4+
- Add `--version` to CLI
45

56
# 5.0
67

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,15 @@ Synchronous form of `rimraf.moveRemove()`
178178
### Command Line Interface
179179

180180
```
181-
rimraf version 4.3.0
181+
rimraf version 6.0.1
182182
183183
Usage: rimraf <path> [<path> ...]
184184
Deletes all files and folders at "path", recursively.
185185
186186
Options:
187187
-- Treat all subsequent arguments as paths
188188
-h --help Display this usage info
189+
--version Display version
189190
--preserve-root Do not remove '/' recursively (default)
190191
--no-preserve-root Do not treat '/' specially
191192
-G --no-glob Treat arguments as literal paths, not globs (default)

src/bin.mts

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Deletes all files and folders at "path", recursively.
2020
Options:
2121
-- Treat all subsequent arguments as paths
2222
-h --help Display this usage info
23+
--version Display version
2324
--preserve-root Do not remove '/' recursively (default)
2425
--no-preserve-root Do not treat '/' specially
2526
-G --no-glob Treat arguments as literal paths, not globs (default)
@@ -158,6 +159,9 @@ const main = async (...args: string[]) => {
158159
} else if (arg === '-h' || arg === '--help') {
159160
console.log(help)
160161
return 0
162+
} else if (arg === '--version') {
163+
console.log(version)
164+
return 0
161165
} else if (arg === '--interactive' || arg === '-i') {
162166
interactive = true
163167
continue
@@ -258,6 +262,7 @@ const main = async (...args: string[]) => {
258262
return 0
259263
}
260264
main.help = help
265+
main.version = version
261266

262267
export default main
263268

test/bin.ts

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ t.test('basic arg parsing stuff', async t => {
5050
CALLS.length = 0
5151
})
5252

53+
t.test('binary version', t => {
54+
const cases = [['--version'], ['a', 'b', '--version', 'c']]
55+
for (const c of cases) {
56+
t.test(c.join(' '), async t => {
57+
t.equal(await bin(...c), 0)
58+
t.same(LOGS, [[bin.version]])
59+
t.same(ERRS, [])
60+
t.same(CALLS, [])
61+
})
62+
}
63+
t.end()
64+
})
65+
5366
t.test('helpful output', t => {
5467
const cases = [['-h'], ['--help'], ['a', 'b', '--help', 'c']]
5568
for (const c of cases) {

0 commit comments

Comments
 (0)