Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ var options = require("nomnom")
.script("jsonlint")
.options({
file: {
list: true,
position: 0,
help: "file to parse; otherwise uses stdin"
help: "file(s) to parse; otherwise uses stdin"
},
version: {
flag : true,
Expand Down Expand Up @@ -131,12 +132,25 @@ function schemaError (str, err) {
function main (args) {
var source = '';
if (options.file) {
var json = path.normalize(options.file);
source = parse(fs.readFileSync(json, "utf8"));
if (options.inplace) {
fs.writeSync(fs.openSync(json,'w+'), source, 0, "utf8");
} else {
if (! options.quiet) { console.log(source)};
for (var i = 0; i < options.file.length; i++) {
var json = path.normalize(options.file[i]);

if (!fs.existsSync(json) || fs.lstatSync(json).isDirectory()) {
if (options.file.length === 1) {
console.error("Unable to find any files matching pattern: ", options.file[i])
return
}
//ignore
return
}

/* we have a real file, read and parse it */
source = parse(fs.readFileSync(json, "utf8"));
if (options.inplace) {
fs.writeSync(fs.openSync(json,'w+'), source, 0, "utf8");
} else {
if (! options.quiet) { console.log(source)};
}
}
} else {
var stdin = process.openStdin();
Expand Down
Loading