1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 | const lib = require('../lib/spaces')
|
6 |
|
7 | function * run (context, heroku) {
|
8 | let spaceName = context.flags.space || context.args.space
|
9 | if (!spaceName) throw new Error('Space name required.\nUSAGE: heroku spaces:info my-space')
|
10 |
|
11 | let headers = {}
|
12 | if (!context.flags.json) {
|
13 | headers = { 'Accept-Expansion': 'region' }
|
14 | }
|
15 |
|
16 | let space = yield heroku.get(`/spaces/${spaceName}`, { headers })
|
17 | if (space.state === 'allocated') {
|
18 | space.outbound_ips = yield heroku.get(`/spaces/${spaceName}/nat`)
|
19 | }
|
20 | render(space, context.flags)
|
21 | }
|
22 |
|
23 | function render (space, flags) {
|
24 | if (flags.json) {
|
25 | cli.log(JSON.stringify(space, null, 2))
|
26 | } else {
|
27 | cli.styledHeader(space.name)
|
28 | cli.styledObject({
|
29 | ID: space.id,
|
30 | Team: space.team.name,
|
31 | Region: space.region.description,
|
32 | CIDR: space.cidr,
|
33 | 'Data CIDR': space.data_cidr,
|
34 | State: space.state,
|
35 | Shield: lib.displayShieldState(space),
|
36 | 'Outbound IPs': lib.displayNat(space.outbound_ips),
|
37 | 'Created at': space.created_at
|
38 | }, ['ID', 'Team', 'Region', 'CIDR', 'Data CIDR', 'State', 'Shield', 'Outbound IPs', 'Created at'])
|
39 | }
|
40 | }
|
41 |
|
42 | module.exports = {
|
43 | topic: 'spaces',
|
44 | command: 'info',
|
45 | description: 'show info about a space',
|
46 | needsAuth: true,
|
47 | args: [{ name: 'space', optional: true, hidden: true }],
|
48 | flags: [
|
49 | { name: 'space', char: 's', hasValue: true, description: 'space to get info of' },
|
50 | { name: 'json', description: 'output in json format' }
|
51 | ],
|
52 | render: render,
|
53 | run: cli.command(co.wrap(run))
|
54 | }
|