diff --git a/cli.js b/cli.js index a56d2fe..5d43fe9 100755 --- a/cli.js +++ b/cli.js @@ -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 diff --git a/test/cli.js b/test/cli.js index 043a53c..d54d73f 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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)) @@ -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') + }) +})