Skip to content

Commit ac2a221

Browse files
authored
Merge pull request #472 from nellh/json-output
Add --json flag to produce machine readable output.
2 parents 923841c + 97c7af6 commit ac2a221

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

bin/bids-validator

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var argv = require('yargs')
1515
.describe('ignoreNiftiHeaders', 'disregard NIfTI header content during validation')
1616
.boolean('verbose')
1717
.describe('verbose', 'Log more extensive information about issues.')
18+
.boolean('json')
19+
.describe('json', 'Output results as JSON.')
1820
.option('config', {
1921
alias: 'c',
2022
describe: 'Optional configuration file. See https://github.com/INCF/bids-validator for more info.'

circle.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ test:
1616
- npm run lint
1717
# Run unit tests
1818
- npm run test
19+
# Smoke tests
20+
- bin/bids-validator tests/data/valid_headers/ --ignoreNiftiHeaders
21+
- bin/bids-validator tests/data/valid_headers/ --ignoreNiftiHeaders --json
1922
# Test gh-pages build
2023
- rm -rf node_modules/
2124
- git checkout gh-pages

cli.js

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,50 @@ var pluralize = require('pluralize');
77
var bytes = require('bytes');
88
var fs = require('fs');
99

10-
module.exports = function (dir, options) {
10+
module.exports = function(dir, options) {
1111
if (fs.existsSync(dir)) {
12-
validate.BIDS(dir, options, function (issues, summary) {
13-
var errors = issues.errors;
14-
var warnings = issues.warnings;
15-
if (issues.errors.length === 1 && issues.errors[0].code === '61') {
16-
console.log(colors.red("The directory " + dir + " failed an initial Quick Test. This means the basic names and structure of the files and directories do not comply with BIDS specification. For more info go to http://bids.neuroimaging.io/"));
17-
} else if (issues.config && issues.config.length >= 1) {
18-
console.log(colors.red('Invalid Config File'));
19-
for (var i = 0; i < issues.config.length; i++) {
20-
var issue = issues.config[i];
21-
issue.file.file = {relativePath: issue.file.path};
22-
issue.files = [issue.file];
12+
if (options.json) {
13+
validate.BIDS(dir, options, function (issues, summary) {
14+
console.log(JSON.stringify({ issues, summary }));
15+
});
16+
} else {
17+
validate.BIDS(dir, options, function (issues, summary) {
18+
var errors = issues.errors;
19+
var warnings = issues.warnings;
20+
if (issues.errors.length === 1 && issues.errors[0].code === "61") {
21+
console.log(
22+
colors.red(
23+
"The directory " +
24+
dir +
25+
" failed an initial Quick Test. This means the basic names and structure of the files and directories do not comply with BIDS specification. For more info go to http://bids.neuroimaging.io/"
26+
)
27+
);
28+
} else if (issues.config && issues.config.length >= 1) {
29+
console.log(colors.red("Invalid Config File"));
30+
for (var i = 0; i < issues.config.length; i++) {
31+
var issue = issues.config[i];
32+
issue.file.file = { relativePath: issue.file.path };
33+
issue.files = [issue.file];
34+
}
35+
logIssues(issues.config, "red", options);
36+
} else if (errors.length >= 1 || warnings.length >= 1) {
37+
logIssues(errors, "red", options);
38+
logIssues(warnings, "yellow", options);
39+
} else {
40+
console.log(
41+
colors.green("This dataset appears to be BIDS compatible.")
42+
);
2343
}
24-
logIssues(issues.config, 'red', options);
25-
} else if (errors.length >= 1 || warnings.length >= 1) {
26-
logIssues(errors, 'red', options);
27-
logIssues(warnings, 'yellow', options);
28-
}
29-
else {
30-
console.log(colors.green("This dataset appears to be BIDS compatible."));
31-
}
32-
logSummary(summary);
33-
if (issues === 'Invalid' || errors && errors.length >= 1 || issues.config && issues.config.length >= 1) {process.exit(1);}
34-
});
44+
logSummary(summary);
45+
if (
46+
issues === "Invalid" ||
47+
(errors && errors.length >= 1) ||
48+
(issues.config && issues.config.length >= 1)
49+
) {
50+
process.exit(1);
51+
}
52+
});
53+
}
3554
} else {
3655
console.log(colors.red(dir + " does not exist"));
3756
process.exit(2);

0 commit comments

Comments
 (0)