add compact option to CLI and update flags to work with latest nomnom api. see #10
This commit is contained in:
21
lib/cli.js
21
lib/cli.js
@@ -11,6 +11,7 @@ var options = require("nomnom")
|
||||
help: "file to parse; otherwise uses stdin"
|
||||
},
|
||||
version: {
|
||||
flag : true,
|
||||
string: '-v, --version',
|
||||
help: 'print version and exit',
|
||||
callback: function() {
|
||||
@@ -18,21 +19,35 @@ var options = require("nomnom")
|
||||
}
|
||||
},
|
||||
sort : {
|
||||
flag : true,
|
||||
string: '-s, --sort-keys',
|
||||
help: 'sort object keys'
|
||||
},
|
||||
inplace : {
|
||||
flag : true,
|
||||
string: '-i, --in-place',
|
||||
help: 'overwrite the file'
|
||||
},
|
||||
indent : {
|
||||
string: '-t CHAR, --indent CHAR',
|
||||
default: " ",
|
||||
"default": " ",
|
||||
help: 'character(s) to use for indentation'
|
||||
},
|
||||
compact : {
|
||||
flag : true,
|
||||
string: '-c, --compact',
|
||||
help : 'compact error display'
|
||||
}
|
||||
})
|
||||
.parseArgs();
|
||||
|
||||
if (options.compact) {
|
||||
var fileName = options.file? options.file + ': ' : '';
|
||||
parser.parseError = parser.lexer.parseError = function(str, hash) {
|
||||
util.puts(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
|
||||
throw new Error(str);
|
||||
};
|
||||
}
|
||||
|
||||
function parse (source) {
|
||||
try {
|
||||
@@ -41,7 +56,9 @@ function parse (source) {
|
||||
parser.parse(source);
|
||||
return JSON.stringify(parsed,null,options.indent);
|
||||
} catch (e) {
|
||||
util.puts(e);
|
||||
if (! options.compact) {
|
||||
util.puts(e);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"lint",
|
||||
"jsonlint"
|
||||
],
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.1+",
|
||||
"preferGlobal": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user