Skip to content
Browse files

cli response transport cleanup

  • Loading branch information...
1 parent 5d6016e commit 197c854812b1f643c635f839959bb56d0a45d376 @jairajs89 committed Mar 7, 2013
Showing with 39 additions and 16 deletions.
  1. +29 −14 client.js
  2. +10 −2 zerver.js
View
43 client.js
@@ -290,24 +290,39 @@
function setupCLI () {
apiSocket.on('eval', function (line, callback) {
- var val, error;
- try {
- val = new Function('return ' + line)();
- }
- catch (err) {
- error = err+'';
- }
- if (typeof val !== 'undefined') {
- try {
- val = JSON.stringify(val);
+ var success, val, error;
+ try {
+ val = new Function('return ' + line)();
+ success = true;
+ error = undefined;
+ }
+ catch (err) {
+ val = undefined;
+ success = false;
+ error = err + '';
+ }
+
+ var type, jsonVal;
+ if (success) {
+ if ((val !== null) && (typeof val === 'object')) {
+ try {
+ jsonVal = JSON.stringify(val);
+ if (typeof jsonVal === 'string') {
+ type = 'json';
+ }
+ }
+ catch (err) {}
}
- catch (err) {
- val = val + '';
+ if ( !type ) {
+ jsonVal = val + '';
+ type = 'string';
}
}
+
callback({
- output : JSON.stringify(val) ,
- error : error
+ error : error ,
+ output : jsonVal ,
+ type : type
});
});
}
View
12 zerver.js
@@ -1240,10 +1240,18 @@ function setupAutoRefresh () {
var socket = getSingleSocket();
if (socket) {
socket.emit('eval', data.cli, function (data) {
- if (data.output) {
+ if (data.type === 'string') {
console.log(data.output);
}
- else if (data.error) {
+ else if (data.type === 'json') {
+ try {
+ console.log( JSON.parse(data.output) );
+ }
+ catch (err) {
+ console.error('(zerver cli error)');
+ }
+ }
+ else {
console.error(data.error);
}
process.send({ prompt: true });

0 comments on commit 197c854

Please sign in to comment.
Something went wrong with that request. Please try again.