2011-12-15 15:12:54 +01:00
|
|
|
|
|
|
|
// JSpec - Shell - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
|
|
|
|
|
|
;(function(){
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
var _quit = quit
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
Shell = {
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
// --- Global
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
main: this,
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
// --- Commands
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
commands: {
|
|
|
|
quit: ['Terminate the shell', function(){ _quit() }],
|
|
|
|
exit: ['Terminate the shell', function(){ _quit() }],
|
|
|
|
p: ['Inspect an object', function(o){ return o.toSource() }]
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
/**
|
|
|
|
* Start the interactive shell.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
start : function() {
|
|
|
|
for (var name in this.commands)
|
|
|
|
if (this.commands.hasOwnProperty(name))
|
|
|
|
this.commands[name][1].length ?
|
|
|
|
this.main[name] = this.commands[name][1] :
|
|
|
|
this.main.__defineGetter__(name, this.commands[name][1])
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-15 15:12:54 +01:00
|
|
|
Shell.start()
|
2016-01-06 00:34:58 +01:00
|
|
|
|
|
|
|
})()
|