forked from bids-standard/legacy-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
45 lines (43 loc) · 1.42 KB
/
cli.js
File metadata and controls
45 lines (43 loc) · 1.42 KB
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
var validate = require('./index.js');
var colors = require('colors/safe');
var fs = require('fs')
module.exports = function (dir, options) {
if (fs.existsSync(dir)) {
validate.BIDS(dir, options, function (errors, warnings) {
if (errors === 'Invalid') {
console.log(colors.red("This does not appear to be a BIDS dataset. For more info go to http://bids.neuroimaging.io/"));
} else if (errors.length >= 1 || warnings.length >= 1) {
logIssues(errors, 'red', options);
logIssues(warnings, 'yellow', options);
}
else {
console.log(colors.green("This dataset appears to be BIDS compatible."));
}
});
} else {
console.log(colors.red(dir + " does not exits"))
}
};
function logIssues (issues, color, options) {
for (var i = 0; i < issues.length; i++) {
var issue = issues[i];
console.log('\t' + colors[color]((i + 1) + ': ' + issue.reason + ' (code: ' + issue.code + ')'));
for (var j = 0; j < issue.files.length; j++) {
var file = issues[i].files[j];
if (!file) {continue;}
console.log('\t\t' + file.file.relativePath);
if (options.verbose) {console.log('\t\t\t' + file.reason);}
if (file.line) {
var msg = '\t\t\t@ line: ' + file.line
if (file.character) {
msg += ' character: ' + file.character
}
console.log(msg)
}
if (file.evidence) {
console.log('\t\t\tEvidence: ' + file.evidence);
}
}
console.log();
}
}