jsonStream should actually stream
This commit is contained in:
parent
ffb0a935a3
commit
f11bf0c247
@ -72,10 +72,11 @@ function boolFromString(value, default_, errName) {
|
||||
* given an array return a string with each element
|
||||
* JSON-stringifed separated by newlines
|
||||
*/
|
||||
function jsonStream(arr) {
|
||||
return arr.map(function (elem) {
|
||||
return JSON.stringify(elem);
|
||||
}).join('\n');
|
||||
function jsonStream(arr, stream) {
|
||||
stream = stream || process.stdout;
|
||||
arr.forEach(function (elem) {
|
||||
stream.write(JSON.stringify(elem) + '\n');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ function do_images(subcmd, opts, args, callback) {
|
||||
// XXX we should have a common method for all these:
|
||||
// XXX sorting
|
||||
// XXX if opts.o is given, then filter to just those fields?
|
||||
console.log(common.jsonStream(imgs));
|
||||
common.jsonStream(imgs);
|
||||
} else {
|
||||
// Add some convenience fields
|
||||
// Added fields taken from imgapi-cli.git.
|
||||
|
@ -99,7 +99,7 @@ function do_instances(subcmd, opts, args, callback) {
|
||||
});
|
||||
|
||||
if (opts.json) {
|
||||
console.log(common.jsonStream(machines));
|
||||
common.jsonStream(machines);
|
||||
} else {
|
||||
tabula(machines, {
|
||||
skipHeader: opts.H,
|
||||
|
@ -22,7 +22,7 @@ function do_keys(subcmd, opts, args, callback) {
|
||||
}
|
||||
|
||||
if (opts.json) {
|
||||
console.log(common.jsonStream(keys));
|
||||
common.jsonStream(keys);
|
||||
} else {
|
||||
// pretty print
|
||||
keys.forEach(function (key) {
|
||||
|
@ -55,7 +55,7 @@ function do_networks(subcmd, opts, args, callback) {
|
||||
}
|
||||
|
||||
if (opts.json) {
|
||||
console.log(common.jsonStream(networks));
|
||||
common.jsonStream(networks);
|
||||
} else {
|
||||
// pretty print
|
||||
tabula(networks, {
|
||||
|
@ -41,7 +41,7 @@ function do_packages (subcmd, opts, args, callback) {
|
||||
return;
|
||||
}
|
||||
if (opts.json) {
|
||||
console.log(common.jsonStream(pkgs));
|
||||
common.jsonStream(pkgs);
|
||||
} else {
|
||||
for (var i = 0; i < pkgs.length; i++) {
|
||||
var pkg = pkgs[i];
|
||||
|
Reference in New Issue
Block a user