Created
November 11, 2012 03:10
-
-
Save larzconwell/4053537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var megarepl = require('./megarepl'); | |
// Create a new command used on every megarepl instance | |
megarepl.createCommand('help', 'Show this help dialog', function () { | |
megarepl.output.pipe('some help info'); // pipe to the default output(process.stdout) | |
return undefined; | |
}); | |
// Create new megarepl instance with options | |
var repl = new megarepl({input: process.stdin, output: process.stdin, prompt: '>>> ', history: 'hist.log', maxHist: 500}); | |
// Create new echo command on this repl instance | |
repl.createCommand('echo', 'Just echo the given arguments', function () { | |
arguments.forEach(function (value) { | |
repl.output.pipe(value); // Pipe to this repl output | |
}); | |
return undefined; | |
}); | |
// Manually add a new command | |
repl.commands['exec'] = {help: 'execute the given code', action: function (code) { | |
var func = new Function(code); | |
return func(); | |
}}; | |
repl.start(); // Start the REPL | |
// Close event(SIGINT, or the exit command) | |
repl.on('close', function () { | |
repl.output.pipe('Exiting...'); | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment