use decorator

This commit is contained in:
Ryan X. Charles 2014-04-15 16:53:23 -03:00
commit 4241287887
3 changed files with 108 additions and 39 deletions

View file

@ -20,14 +20,31 @@ var main = function() {
var args = commander.args;
try {
api._command(args[0], args.slice(1), function(err, result) {
var command = args[0];
var commandArgs = args.slice(1);
if (command[0] == '_' || typeof api[command] != 'function')
throw new Error('invalid command');
api[command].apply(api, commandArgs.concat([function(err, result) {
if (err)
return console.log("" + err);
console.log(JSON.stringify(result, null, 2));
});
} catch (err) {
console.log("" + err);
}]));
} catch(err) {
if (err.toString() == 'Error: invalid command') {
console.log("" + err);
}
else if (err.toString() == 'Error: invalid arguments') {
console.log("" + err);
console.log('Arguments for ' + command + ':')
api.getArgTypes(command, function(err, result) {
console.log(JSON.stringify(result, null, 2));
});
}
else
throw (err);
}
};