Skip to content

Commit 2ffd918

Browse files
committed
add --version -V to show version
1 parent 148ef61 commit 2ffd918

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/bin.mts

+8-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ const j = jack({
215215
description: `Output a huge amount of noisy debug information about
216216
patterns as they are parsed and used to match files.`,
217217
},
218-
})
219-
.flag({
218+
version: {
219+
short: 'V',
220+
description: `Output the version (${version})`,
221+
},
220222
help: {
221223
short: 'h',
222224
description: 'Show this usage information',
@@ -225,6 +227,10 @@ const j = jack({
225227

226228
try {
227229
const { positionals, values } = j.parse()
230+
if (values.version) {
231+
console.log(version)
232+
process.exit(0)
233+
}
228234
if (values.help) {
229235
console.log(j.usage())
230236
process.exit(0)

tap-snapshots/test/bin.ts.test.cjs

+27
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,35 @@ Object {
143143
-v --debug Output a huge amount of noisy debug information about
144144
patterns as they are parsed and used to match files.
145145
146+
-V --version Output the version ({VERSION})
146147
-h --help Show this usage information
147148
148149
),
149150
}
150151
`
152+
153+
exports[`test/bin.ts > TAP > version > --version shows version 1`] = `
154+
Object {
155+
"args": Array [
156+
"--version",
157+
],
158+
"code": 0,
159+
"options": Object {},
160+
"signal": null,
161+
"stderr": "",
162+
"stdout": "{VERSION}\\n",
163+
}
164+
`
165+
166+
exports[`test/bin.ts > TAP > version > -V shows version 1`] = `
167+
Object {
168+
"args": Array [
169+
"-V",
170+
],
171+
"code": 0,
172+
"options": Object {},
173+
"signal": null,
174+
"stderr": "",
175+
"stdout": "{VERSION}\\n",
176+
}
177+
`

test/bin.ts

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ t.test('usage', async t => {
5656
t.match(badp.stderr, 'Invalid value provided for --platform: "glorb"\n')
5757
})
5858

59+
t.test('version', async t => {
60+
t.matchSnapshot(await run(['-V']), '-V shows version')
61+
t.matchSnapshot(await run(['--version']), '--version shows version')
62+
})
63+
5964
t.test('finds matches for a pattern', async t => {
6065
const cwd = t.testdir({
6166
a: {

0 commit comments

Comments
 (0)