Skip to content

Commit 8cb3f6a

Browse files
committed
Allow using a pipe for jsome-cli
1 parent 6bbea74 commit 8cb3f6a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

bin/cli.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,19 @@ jsome.level.spaces = argv.s;
3939

4040
var filePath = argv._[0] || '';
4141

42-
fs.exists(path.resolve(filePath), function (exists) {
43-
if(!exists) return jsome({ error : "File doesn't exists" });
44-
fs.readFile(path.resolve(filePath), function (error, jsonString) {
45-
if(error) return jsome ({ error : error.message });
46-
jsome.parse(jsonString.toString());
42+
if(filePath) {
43+
fs.exists(path.resolve(filePath), function (exists) {
44+
if(!exists) return jsome({ error : "File doesn't exist" });
45+
fs.readFile(path.resolve(filePath), function (error, jsonString) {
46+
if(error) return jsome ({ error : error.message });
47+
jsome.parse(jsonString.toString());
48+
});
4749
});
48-
});
50+
} else {
51+
process.stdin.resume();
52+
process.stdin.setEncoding('utf8');
53+
54+
process.stdin.on('data', function (data) {
55+
jsome(JSON.parse(data));
56+
});
57+
}

0 commit comments

Comments
 (0)