Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add compact option to CLI and update flags to work with latest nomnom…

… api. see #10
  • Loading branch information...
commit 1956caa5a40b973524e0aeae4734905916435784 1 parent 5a52ba4
@millermedeiros millermedeiros authored
Showing with 22 additions and 5 deletions.
  1. +21 −4 lib/cli.js
  2. +1 −1  package.json
View
25 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,30 +19,46 @@ 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 {
var parsed = options.sort ?
sortObject(parser.parse(source)) :
- parser.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);
}
}
@@ -49,7 +66,7 @@ function parse (source) {
function main (args) {
var source = '';
if (options.file) {
- var path = require('path').join(process.cwd(), options.file);
+ var path = require('path').join(process.cwd(), options.file);
source = parse(fs.readFileSync(path, "utf8"));
if (options.inplace) {
fs.writeSync(fs.openSync(path,'w+'), source, 0, "utf8");
View
2  package.json
@@ -8,7 +8,7 @@
"lint",
"jsonlint"
],
- "version": "1.2.1",
+ "version": "1.2.1+",
"preferGlobal": true,
"repository": {
"type": "git",
Please sign in to comment.
Something went wrong with that request. Please try again.