Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --version flag for CLI #308

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading