ACLI is a command line interface, developed mainly for the use in the anode project.
A Polymer control wrapping this component is now available here
Before starting to work on this module, few other existing open source CLI (command line interface) components were evaluated, like
- GCLI
- JQuery Terminal
- JQuery Console
- JS Sandbox Console
- and more...
Each of the above components and the others that were examined had some of the required functionality, but did not support other features that we needed.
The most suitable library for this task was the GCLI component, which was the main inspiration for implementing ACLI, mostly at the area of the commands structure.
- Manages environment variables and use them as part of the command line.
- Supports plugins- remote commands integrated into the console, using docRouter metadata.
Supporting plugins with client side processing and styling. - Keeps command line history, plugins and environment variables in offline storage.
- Pin Panel feature to keep command execution results on-screen.
- Visualizes json data as an html table with auto collapsing deep elements.
- Supports working in parallel with few instances/tabs of the console.
- Supports broadcasting requests when working on a farm.
Extended documentation is available in the docs folder
The following is an example of how to quickly start using the component.
See the basic
sample under the samples
directory.
html file:
<body>
<div class="cli-control"></div>
</body>
js file:
var cli = $(".cli-control").cli(
{
environment: {user: { type: 'string', value: '', description: 'The current user' }},
commands: getCommands(),
context: { some: 'object' },
welcomeMessage: "Welcome to anode console!<br/>. Type <b>help</b> to start exploring the commands currently supported!<br/>"
}
);
// create default commands
function getCommands() {
var commands = [];
var addCommand = {
name: 'add',
description: 'add two numbers',
usage: 'add num1 num2',
example: 'add 4 5',
params: [
{
name: 'num1',
description: 'first number',
type: 'number'
},
{
name: 'num2',
description: 'second number',
type: 'number'
}
],
exec: function(args, context) {
return args.num1 + args.num2;
}
}
var asyncCommand = {
name: 'async',
description: 'simulates async command',
usage: 'async [text]',
example: 'async',
params: [
{
name: 'text',
description: 'some text to show',
type: 'string',
defaultValue: null // make this an optional argument
}
],
exec: function(args, context) {
var promise = context.createPromise();
// simulating some async long-processing action
setTimeout(function(){
var result = args.text || "you didn't enter text";
promise.resolve(result);
}, 1000);
return promise;
}
}
commands.push(addCommand);
commands.push(asyncCommand);
return commands;
}
See plugins
under samples
folder for a node JS sample application that extends the console with commands from the server (plug-ins)!
Main requirements and detailed design can be found in the design file.
Enjoy!