-
Notifications
You must be signed in to change notification settings - Fork 11
/
fliplet-organization.js
53 lines (42 loc) · 1.36 KB
/
fliplet-organization.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const _ = require('lodash');
const auth = require('./lib/auth');
const organizations = require('./lib/organizations');
const config = require('./lib/config');
const organizationId = Number(process.argv[2]);
if (!organizationId) {
console.log('Organization reset');
return config.set('organization', null);
}
if (process.argv[3] === '--force') {
config.set('organization', { id: organizationId });
console.log(`Organization set to ID ${organizationId}`);
return;
}
organizations.getOrganizationsList()
.then(function(organizations) {
var organization = _.find(organizations, { id: organizationId });
if (organization) {
config.set('organization', organization);
console.log(`Organization set to ${organization.name}`);
return;
}
auth.isAdmin()
.then(function(isAdmin) {
if (isAdmin) {
organization = { id: organizationId };
config.set('organization', organization);
console.log('Organization set.');
return;
}
console.log('You do not belong to that organization. List organizations you belong with: fliplet list-organizations');
process.exit(1);
})
.catch(function(error) {
console.log(error);
process.exit(1);
});
})
.catch(function onGetOrganizationsError(error) {
console.error(error);
process.exit(1);
});