use decorator
This commit is contained in:
parent
34f30e88ea
commit
4241287887
3 changed files with 108 additions and 39 deletions
25
bin/copay
25
bin/copay
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue