Skip to content

Commit 1531ce2

Browse files
committed
minor clean up of CLI code
1 parent 0237f90 commit 1531ce2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

bin/pixelmatch

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ if (process.argv.length < 4) {
1212
process.exit(64);
1313
}
1414

15-
const img1Path = process.argv[2];
16-
const img2Path = process.argv[3];
17-
const diffPath = process.argv[4];
18-
const threshold = isNaN(+process.argv[5]) ? undefined : +process.argv[5];
19-
const includeAA = process.argv[6] === 'true';
15+
const [,, img1Path, img2Path, diffPath, threshold, includeAA] = process.argv;
16+
const options = {
17+
threshold: +threshold,
18+
includeAA: includeAA !== undefined && includeAA !== 'false'
19+
};
2020

2121
const img1 = PNG.sync.read(fs.readFileSync(img1Path));
2222
const img2 = PNG.sync.read(fs.readFileSync(img2Path));
@@ -31,15 +31,13 @@ if (img2.width !== width || img2.height !== height) {
3131
const diff = diffPath ? new PNG({width, height}) : null;
3232

3333
console.time('matched in');
34-
const diffs = match(img1.data, img2.data, diff ? diff.data : null, width, height, {threshold, includeAA});
34+
const diffs = match(img1.data, img2.data, diff ? diff.data : null, width, height, options);
3535
console.timeEnd('matched in');
3636

3737
console.log(`different pixels: ${diffs}`);
3838
console.log(`error: ${Math.round(100 * 100 * diffs / (width * height)) / 100}%`);
3939

40-
const exitCode = diffs ? 66 : 0;
41-
4240
if (diff) {
4341
fs.writeFileSync(diffPath, PNG.sync.write(diff));
4442
}
45-
process.exit(exitCode);
43+
process.exit(diffs ? 66 : 0);

0 commit comments

Comments
 (0)