1 | 'use strict'
|
2 |
|
3 | let cli = require('heroku-cli-util')
|
4 | let co = require('co')
|
5 | let Utils = require('../../lib/utils')
|
6 |
|
7 | function * run (context, heroku) {
|
8 | let orgs = yield heroku.get('/organizations')
|
9 | let teams = orgs.filter(o => o.type === 'team')
|
10 |
|
11 |
|
12 | if (context.flags.teams) {
|
13 | orgs = teams
|
14 | } else if (context.flags.enterprise) {
|
15 | orgs = orgs.filter(o => o.type === 'enterprise')
|
16 | }
|
17 |
|
18 | if (context.flags.json) {
|
19 | Utils.printGroupsJSON(orgs)
|
20 | } else {
|
21 | Utils.printGroups(orgs, {label: 'Organizations'})
|
22 | }
|
23 |
|
24 | if ((teams.length) && (!context.flags.teams) && (!context.flags.enterprise)) {
|
25 | cli.warn(`To list your teams only you can use ${cli.color.cmd('heroku teams')}`)
|
26 | }
|
27 | }
|
28 |
|
29 | module.exports = {
|
30 | topic: 'orgs',
|
31 | description: 'list the organizations that you are a member of',
|
32 | needsAuth: true,
|
33 | flags: [
|
34 | {name: 'json', description: 'output in json format'},
|
35 | {name: 'enterprise', hasValue: false, description: 'filter by enterprise orgs'},
|
36 | {name: 'teams', hasValue: false, description: 'filter by teams'}
|
37 | ],
|
38 | run: cli.command(co.wrap(run))
|
39 | }
|