gear-cli
Version:
Adds CLI to Gearbox
152 lines (118 loc) • 4.96 kB
JavaScript
var Gearbox = require('gearbox');
var expect = require('chai').expect;
var cache;
var box;
var cliGear;
describe ('Setup for basic cli tests', function() {
this.timeout(50000);
it('should get a new Gearbox instance for basic cli tests', function () {
box = new Gearbox(
{
gearConfig: {
dao: {
dataSource: {
connector: 'memory'
// connector: 'postgresql',
// host: 'localhost',
// port: 5432,
// database: 'gearbox',
// username: 'gearbox',
// password: 'gearbox'
}
},
cli: {
debug: true,
commands: [
{
name: 'user',
options: {
description: 'User options',
help: 'For maintaining users'
},
args: [
{
name: ['-a', '--action'],
options: {
action: 'store',
dest: 'action',
choices: ['create', 'delete']
}
},
{
name: ['-e --email'],
options: {
help: 'E-mail identifying the user',
dest: 'email',
action: 'store'
}
},
{
name: ['-p --password'],
options: {
help: 'Password to authenticate user',
dest: 'password',
action: 'store'
}
}
],
gear: {
name: 'loopback',
method: 'userCli'
}
},
{
name: 'gear',
options: {
description: 'Gearbox options',
help: 'Basic app things'
},
args: [
{
name: ['-l', '--locate'],
options: {
action: 'store',
dest: 'locate'
}
}
],
gear: {
name: 'gearbox',
method: 'gearboxCli'
}
}
]
}
}
}
);
});
it('should explicitly add dir containing cli gear', function () {
box.registerGearPath('cli', __dirname, './..');
});
it ('should get gear for basic cli tests', function(done) {
box.get(['cli', 'cache'], {}, function(err, gears) {
expect(err).to.equal(null);
cliGear = gears.cli;
cache = gears.cache;
done();
});
});
it ('should parse a basic command line', function() {
var result = cliGear._parseArgs(['user','--action', 'create']);
expect(result.args.commandName).to.eql('user');
expect(result.args.action).to.eql('create');
expect(result.args.email).to.eql(null);
expect(result.args.password).to.eql(null);
expect(result.gear.name).to.eql('loopback');
expect(result.gear.method).to.eql('userCli');
});
it ('should run a basic command line', function(done) {
var result = cliGear.run (
['gear','--locate', 'blueprint'],
function (err) {
expect(err).to.equal(null);
done();
}
);
});
});