Skip to content

Commit

Permalink
Add --format switch, write response body without parsing it
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli committed Oct 4, 2012
1 parent c3906af commit 1200379
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/cdbsql
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ function usage(exit_code) {
console.log(" --port <num> service tcp port number (8080)");
console.log(" --api-version <num> API version (1)");
console.log(" --key <string> API authentication key (none)");
console.log(" --format <string> Response format (json)");
process.exit(exit_code);
}

process.argv.shift(); // this will be "node" (argv[0])
process.argv.shift(); // this will be "benchmark.js" (argv[1])

var format = 'json';
var username;
var domain = 'localhost';
var port = 8080;
Expand Down Expand Up @@ -54,6 +56,9 @@ while ( arg = process.argv.shift() ) {
else if ( arg == '--api-version' ) {
api_version = process.argv.shift();
}
else if ( arg == '--format' ) {
format = process.argv.shift();
}
else if ( ! sql ) {
sql = arg;
}
Expand All @@ -71,7 +76,7 @@ var hostname = username + '.' + domain;
var opt = {
host: hostname,
port: port,
path: '/api/v' + api_version + '/sql?q=' + encodeURIComponent(sql)
path: '/api/v' + api_version + '/sql?q=' + encodeURIComponent(sql) + '&format=' + encodeURIComponent(format)
};

console.log("Requests:", 'http://' + opt.host + ':' + opt.port + opt.path);
Expand All @@ -87,8 +92,7 @@ http.get(opt, function(res) {

res.on('end', function() {
console.log('Body:');
var json = JSON.parse(body);
console.dir(json);
console.dir(body);
});
}).on('error', function(e) {
console.log("ERROR: " + e.message);
Expand Down

0 comments on commit 1200379

Please sign in to comment.