Skip to content

Commit

Permalink
fix: process --version Flag Directly (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindluni committed Oct 4, 2022
1 parent 0bdcf04 commit eee0fb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli.js
Expand Up @@ -56,6 +56,12 @@ Flags (advanced):
return
}

if (argv.version) {
console.log(cliOptions.version)
process.exitCode = 0
return
}

cliOptions.eslintConfig.overrideConfig.parserOptions.project = _getTSConfigPath(
CURRENT_WORKING_DIRECTORY,
argv.project
Expand Down
18 changes: 18 additions & 0 deletions test/cli.js
Expand Up @@ -2,6 +2,7 @@ import { fileURLToPath } from 'node:url'

import test from 'tape'
import crossSpawn from 'cross-spawn'
import options from '../options.js'

const CLI_PATH = fileURLToPath(new URL('../cli.js', import.meta.url))

Expand All @@ -16,3 +17,20 @@ test('command line usage: --help', (t) => {
t.equal(code, 0, 'zero exit code')
})
})

test('command line usage: --version', (t) => {
t.plan(2)

const child = crossSpawn(CLI_PATH, ['--version'])
child.on('error', (err) => {
t.fail(err)
})

child.stdout.on('data', (data) => {
t.equal(data.toString().trim(), options.version, 'version matches')
})

child.on('close', (code) => {
t.equal(code, 0, 'zero exit code')
})
})

0 comments on commit eee0fb5

Please sign in to comment.