Skip to content

Commit

Permalink
Added .debug and .headers repl commands, upped the package number and…
Browse files Browse the repository at this point in the history
… updated the README
  • Loading branch information
davglass committed Feb 24, 2011
1 parent d8958b8 commit 32b0864
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ A NodeJS REPL environment preloaded with a Y variable populated by a YUI sandbox
.io http://yuilibrary.com/gallery/api/show/yql
</pre>

`.headers {url}` Make an IO request to the passed URL and return the headers
<pre class="console">
.headers https://graph.facebook.com/davglass
.headers http://yuilibrary.com/gallery/api/show/yql
</pre>

`.yql {sql}` Make an YQL request with the passed SQL statement
<pre class="console">
.yql select * from weather.forecast where location=90210
.yql select * from flickr.photos.recent
</pre>

`.debug` Toggle the debug config on the YUI instance, outputs the new debug setting.
<pre class="console">
.debug
</pre>

## Screencast

Here is a simple little screencast of it in action: [View Video](http://dl.dropbox.com/u/5669457/YUI3-REPL-2.mov)
51 changes: 43 additions & 8 deletions bin/yui-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ require('colors');

var Y = require('yui3').silent().useSync('yui-base');

Y.toString = function() {
return 'Dav was here..'
};

var repl = replServer.start('YUI@' + Y.version + '> ');

var debug = false;

var ctx = repl.context;
ctx.Y = Y;

Expand All @@ -37,7 +35,16 @@ var load = function(url) {
});
};


repl.defineCommand('debug', {
help: 'Toggle the YUI debug config option',
action: function() {
var d = !debug+'';
debug = !debug;
this.outputStream.write('Setting debug on the Y instance to: '.magenta + d.white + '\n');
this.context.Y.config.debug = debug;
this.displayPrompt();
}
});

repl.defineCommand('import', {
help: 'Import a document into this context',
Expand Down Expand Up @@ -84,14 +91,38 @@ repl.defineCommand('io', {
on: {
complete: function(id, e) {
self.outputStream.write(' [done]\n'.white);
self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): Content-Type: "' + e.headers['content-type'].green + '"\n\n'.white);
var str;
try {
str = util.inspect(JSON.parse(e.responseText), false, Infinity, true);
} catch (e) {
str = e.responseText
str = e.responseText;
}
self.outputStream.write(str);
self.outputStream.write('\n');
self.outputStream.write('\n\n');
self.displayPrompt();
}
}
});
});
}
});

repl.defineCommand('headers', {
help: 'Make an IO request to the passed URL and only return the headers',
action: function(url) {
var self = this,
Y = this.context.Y;
self.outputStream.write('Making IO Request: '.magenta + url.yellow);
Y.use('io', function() {
Y.io(url, {
on: {
complete: function(id, e) {
self.outputStream.write(' [done]\n'.white);
self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): Content-Type: "' + e.headers['content-type'].green + '"\n\n'.white);
var str = util.inspect(e.headers, false, Infinity, true);
self.outputStream.write(str);
self.outputStream.write('\n\n');
self.displayPrompt();
}
}
Expand All @@ -116,10 +147,14 @@ repl.defineCommand('yql', {
str = util.inspect(r, false, Infinity, true);
}
self.outputStream.write(str);
self.outputStream.write('\n');
self.outputStream.write('\n\n');
self.displayPrompt();
});
});
}
});


process.on('uncaughtException', function(e) {
Y.log(e.stack, 'error', 'repl');
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yui-repl",
"description": "YUI 3 Powered REPL",
"version": "0.0.2",
"version": "0.0.3",
"author": "Dav Glass <davglass@gmail.com>",
"bugs": { "web": "http://github.com/davglass/yui-repl/issues" },
"os": [ "darwin", "linux" ],
Expand Down

0 comments on commit 32b0864

Please sign in to comment.