Permalink
Browse files

add preliminary --format support

  • Loading branch information...
1 parent a68674d commit c25821256df6b554722c2cb787966cbdd63cffb0 @tj committed Nov 7, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 bin/jog
View
18 bin/jog
@@ -65,6 +65,7 @@ program
.option('-r, --reduce <fn>', 'use the given <fn> for reducing')
.option('-c, --color', 'color the output')
.option('-j, --json', 'output JSON (--color will not work)')
+ .option('--format <fmt>', 'output format string')
.parse(process.argv);
// determine store
@@ -95,6 +96,16 @@ if (program.reduce) {
var reduce = new Function('$, _', 'return ' + program.reduce);
}
+// --format
+
+if (program.format) {
+ var format = '"' + program.format.replace(/(\.[.\w]+)/g, function(_, str){
+ return '" + _' + str + ' + "';
+ }) + '"';
+
+ format = new Function('_', 'return ' + format);
+}
+
// setup
var log = jog(store)
@@ -146,6 +157,13 @@ stream.on('end', function(){
*/
function output(obj) {
+ if (format) {
+ obj = obj.map(format).forEach(function(str){
+ console.log(str);
+ });
+ return;
+ }
+
if (program.json) {
console.log(JSON.stringify(obj, null, 2));
} else if (program.color) {

0 comments on commit c258212

Please sign in to comment.