UNPKG

2.37 kBJavaScriptView Raw
1var validator = require('validator');
2var Domo = require('ryuu-client-beta');
3var Manifest = require('../util/manifest');
4var Login = require('../util/login');
5var evoke = require('../util/evoke');
6var log = require('../util/log');
7var constants = require('../util/constants');
8
9module.exports = function(program){
10 program
11 .command('owner <add|rm|ls> [user-emails]')
12 .description('manage design owners')
13 .option('-i, --design_id <id>', 'Specify design ID, otherwise it is retrieved from a manifest file')
14 .action(function(action, users, options) {
15
16 var designId;
17 if (options.design_id) {
18 designId = options.design_id;
19 if (!designId || !validator.isUUID(designId)) return log.fail('The value specified for option -i is not a valid design ID', designId);
20 } else {
21 var manifest = Manifest.get(program.manifest);
22 if (!manifest) return log.fail('No manifest found. Please supply design id using -i or change to a directory with a valid manifest file');
23 if (!manifest.id) return log.fail('No manifest id. Please publish your design before attempting to add owners to it.');
24 designId = manifest.id;
25 }
26
27 var login = Login.getMostRecentLogin();
28 Login.verifyLogin(login);
29
30 var domo = new Domo(login.instance, login.refreshToken, constants.CLIENT_ID);
31
32 switch(action) {
33 case 'add':
34 if (users) {
35 domo.addOwners(designId, users)
36 .tap(evoke(log.ok, 'Owners added ' + users))
37 .catch(evoke(log.fail, 'Error adding owners'))
38 .finally(process.exit)
39 }
40 break;
41 case 'rm':
42 if (users) {
43 domo.removeOwners(designId, users)
44 .tap(evoke(log.ok, 'Owners removed ' + users))
45 .catch(evoke(log.fail, 'Error removing owners'))
46 .finally(process.exit)
47 }
48 break;
49 case 'ls':
50 domo.getOwners(designId)
51 .tap(function listUsers(res) {
52 res.sort();
53 log.ok("Owners for design " + designId);
54 res.forEach(function(element, index, array) {
55 console.log("\t" + element);
56 });
57 })
58 .catch(evoke(log.fail, 'Error retrieving owners'))
59 .finally(process.exit)
60 break;
61 }
62 });
63}