Skip to content

Commit 8c51587

Browse files
committed
fix: --max option considers minor, patch and suffix
`--max 2018.3` includes all 2018.3.x versions. `--max 2018.3.1` includes all 2018.3.1.x versions, but excludes 2018.3.1x.y versions
1 parent 2805146 commit 8c51587

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

bin/cli.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
const { getUnityChangeset, scrapeArchivedChangesets, scrapeBetaChangesets } = require("../dist/index");
44
const cli = require('cac')();
55

6-
toNumber = function (version) {
6+
toNumber = function (version, max = false) {
77
const match = version.toString().match(/^(\d+)\.*(\d*)\.*(\d*)(\w*)(\d*)$/);
88
if (match === null) return 0;
99

10-
return parseInt(match[1] || '0') * 100 * 100 * 100 * 100
11-
+ parseInt(match[2] || '0') * 100 * 100 * 100
12-
+ parseInt(match[3] || '0') * 100 * 100
13-
+ ((match[4] || 'a').toUpperCase().charCodeAt(0) - 65) * 100
14-
+ parseInt(match[5] || '0');
10+
return parseInt(match[1] || (max ? '9999' : '0')) * 100 * 100 * 100 * 100
11+
+ parseInt(match[2] || (max ? '99' : '0')) * 100 * 100 * 100
12+
+ parseInt(match[3] || (max ? '99' : '0')) * 100 * 100
13+
+ ((match[4] || (max ? 'z' : 'a')).toUpperCase().charCodeAt(0) - 65) * 100
14+
+ parseInt(match[5] || (max ? '99' : '0'));
1515
};
1616

1717
cli.command('<version>', 'Get a changeset for specific version')
18-
.action((version, options) => (async () => {
18+
.action(version => (async () => {
1919
try {
2020
var changeset = await getUnityChangeset(version);
2121
console.log(changeset.changeset);
@@ -42,10 +42,13 @@ cli.command('list', 'List changesets')
4242

4343
// Filter by min/max.
4444
var min = options.min ? toNumber(options.min) : Number.MIN_VALUE;
45-
var max = options.max ? toNumber(options.max) : Number.MAX_VALUE;
45+
var max = options.max ? toNumber(options.max, true) : Number.MAX_VALUE;
4646
results = results
47-
.filter(r => r.version.includes(options.grep || ''))
48-
.filter(r => min <= toNumber(r.version) && toNumber(r.version) <= max);
47+
.filter(r => options.grep ? r.version.includes(options.grep) : true)
48+
.filter(r => {
49+
const n = toNumber(r.version);
50+
return min <= n && n <= max;
51+
});
4952

5053
if (options.json) {
5154
if (options.versions)

0 commit comments

Comments
 (0)