Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created November 11, 2012 03:10
Show Gist options
  • Save larzconwell/4053537 to your computer and use it in GitHub Desktop.
Save larzconwell/4053537 to your computer and use it in GitHub Desktop.
#!/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