diff --git a/README.md b/README.md index 1d76664..ecb5442 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,46 @@ This repository is managed by the [Package Maintenance Working Group](https://github.com/nodejs/package-maintenance), see [Governance](https://github.com/nodejs/package-maintenance/blob/master/Governance.md). - - ## Usage ``` $ npm i @pkgjs/nv ``` +``` +$ npx @pkgjs/nv --help + +nv + +Commands: + nv ls [versions...] List Node.js versions [aliases: show] + +Options: + --help Show help [boolean] + --version Show version number [boolean] + +``` + +``` +$ npx @pkgjs/nv ls --help + +nv ls [versions...] + +List Node.js versions + +Options: + --help Show help [boolean] + --version Show version number [boolean] + --mirror mirror url to load from + [string] [default: https://nodejs.org/dist/] + --pretty-json Pretty print json + [string] [default: pretty print json spaces, default 2 (--no-pretty-json for + new line delimted json)] + --latest-of-major-only Only show latest version in each semver major range + [boolean] [default: false] + --versions [default: "lts_active"] +``` + ```javascript const nv = require('@pkgjs/nv') diff --git a/bin/nv b/bin/nv index 6d137a2..18fc9a9 100755 --- a/bin/nv +++ b/bin/nv @@ -18,10 +18,16 @@ require('yargs') defaultDescription: 'pretty print json spaces, default 2 (--no-pretty-json for new line delimted json)', description: 'Pretty print json' }) + yargs.option('latest-of-major-only', { + type: 'boolean', + default: false, + description: 'Only show latest version in each semver major range' + }) }, handler: (argv) => { nv(argv.versions, { - mirror: argv.mirror + mirror: argv.mirror, + latestOfMajorOnly: argv.latestOfMajorOnly }) .then(result => { result.forEach(r => { diff --git a/test/cli.js b/test/cli.js index 66f5f59..bfca428 100644 --- a/test/cli.js +++ b/test/cli.js @@ -27,4 +27,14 @@ suite('nv cli', () => { assert(r.version.startsWith('8.')) }) }) + test('should only contain the latest of each major', () => { + const result = execFileSync(nv, ['ls', '16.x || 18.x', '--no-pretty-json', '--latest-of-major-only'], { cwd: cwd }) + .toString().trim().split('\n') + .map((line) => JSON.parse(line)) + + assert(Array.isArray(result)) + assert.strictEqual(result.length, 2) + assert(result[0].version.startsWith('16.')) + assert(result[1].version.startsWith('18.')) + }) })