Skip to content

Commit abfadd3

Browse files
committed
feat(cli): expose --latest-of-major-only option
1 parent ee7a4b9 commit abfadd3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

bin/nv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ require('yargs')
1818
defaultDescription: 'pretty print json spaces, default 2 (--no-pretty-json for new line delimted json)',
1919
description: 'Pretty print json'
2020
})
21+
yargs.option('latest-of-major-only', {
22+
type: 'boolean',
23+
default: false,
24+
description: 'Only show latest version in each semver major range'
25+
})
2126
},
2227
handler: (argv) => {
2328
nv(argv.versions, {
24-
mirror: argv.mirror
29+
mirror: argv.mirror,
30+
latestOfMajorOnly: argv.latestOfMajorOnly
2531
})
2632
.then(result => {
2733
result.forEach(r => {

test/cli.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ suite('nv cli', () => {
2727
assert(r.version.startsWith('8.'))
2828
})
2929
})
30+
test('should only contain the latest of each major', () => {
31+
const result = execFileSync(nv, ['ls', '16.x || 18.x', '--no-pretty-json', '--latest-of-major-only'], { cwd: cwd })
32+
.toString().trim().split('\n')
33+
.map((line) => JSON.parse(line))
34+
35+
assert(Array.isArray(result))
36+
assert.strictEqual(result.length, 2)
37+
assert(result[0].version.startsWith('16.'))
38+
assert(result[1].version.startsWith('18.'))
39+
})
3040
})

0 commit comments

Comments
 (0)