-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_check.js
executable file
·61 lines (50 loc) · 1.48 KB
/
run_check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
const argparse = require('argparse');
const {promisify} = require('util');
const config_module = require('./src/config');
const database = require('./src/database');
const check = require('./src/check');
const {cmp_key} = require('./src/utils');
async function main() {
const parser = new argparse.ArgumentParser({description: 'Run checks interactively'});
parser.add_argument('-s', '--season', {
help: 'key of the season to select. By default the newest season will be selected',
});
parser.add_argument('-j', '--json', {
action: 'store_true',
help: 'Output found problems as JSON',
});
const args = parser.parse_args();
const app_cfg = await promisify(config_module.load)();
const db = await database.async_init();
// select season
let seasons = await db.async_fetch_all([{
collection: 'seasons',
}]);
if (args.season) {
seasons = seasons.filter(s => s.key === args.season);
if (!seasons.length) {
parser.error(`Could not find season ${JSON.stringify(args.season)}`);
}
}
seasons.sort(cmp_key('key'));
const season = seasons[seasons.length - 1];
// run checks in that season
const {found} = await promisify(check.run_recheck)(season);
// Write check output
if (args.json) {
console.log(JSON.stringify(found, undefined, 2));
return;
}
for (const problem of found) {
console.log(problem.message);
}
}
(async () => {
try {
await main();
} catch (e) {
console.error(e.stack);
process.exit(2);
}
})();