Package Exports
- shell
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shell) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Shell - Full features and pretty console applications
Create nice looking shell applications in minutes with a Connect inspired API.
Quick exemple, a redis client
var spawn = require('child_process').spawn,
shell = require('shell'),
app = new shell.Shell(),
styles = app.styles;
app.configure(function(){
app.use( shell.history({shell: app}) );
app.use( shell.completer({shell: app}) );
app.use( shell.help({shell: app, introduction: true}) );
});
app.on('exit', function(){
if(app.server){ app.server.kill(); }
if(app.client){ app.client.quit(); }
});
app.cmd('start', 'Start the redis server', function(params, next){
app.server = spawn('redis-server', [__dirname+'/redis.conf']);
next();
});
app.cmd('keys :pattern', 'Find keys', function(params, next){
if(!app.client){
app.client = require('redis').createClient();
}
app.client.keys(params.pattern, function(err, keys){
if(err){ return style.red(err.message), next(); }
styles.cyan(keys.join('\n'));
next();
});
});
Installation
`npm install shell`
Creating and configuring
var app = new shell.Shell();
app.configure(function(){
app.use( shell.history({shell: app}) );
app.use( shell.completer({shell: app}) );
app.use( shell.help({shell: app, introduction: true}) );
});
The constructor shell.Shell
take an optional object. options are
- stdin, Source to read from
- stdout, Destination to write to
Like with Express, app.configure
allows the customization of plugins for different environments (however, it is not yet implemented) while app.use
register plugins.
History plugin
Persist command history between multiple sessions. Options passed during creation are:
- shell, required
- historyFile, default to process.cwd()+'/.node_shell'
Completer plugin
Provide tab completion. Options passed during creation are: - shell, required
Help plugin
Display help when use type "help" or when he press enter
on empty prompt. Command help is only displayed if a description was provided during the command registration. Additionnaly, a new shell.help()
function is made available. Options passed during creation are:
- shell, required
- introduction, Print message 'Type "help" or press enter for a list of commands' if boolean true or a custom message if a string