1 | 'use strict'
|
2 |
|
3 | let cli = require('heroku-cli-util')
|
4 | let co = require('co')
|
5 |
|
6 | let grandfatheredPrice = require('../../lib/util').grandfatheredPrice
|
7 | let formatPrice = require('../../lib/util').formatPrice
|
8 | let formatState = require('../../lib/util').formatState
|
9 | let style = require('../../lib/util').style
|
10 |
|
11 | let run = cli.command({preauth: true}, function (ctx, api) {
|
12 | const resolve = require('../../lib/resolve')
|
13 | return co(function * () {
|
14 | let resolvedAddon = yield resolve.addon(api, ctx.app, ctx.args.addon)
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | let [addon, attachments] = yield [
|
20 | api.get(`/addons/${resolvedAddon.id}`, {headers: {
|
21 | 'Accept-Expansion': 'addon_service,plan',
|
22 | 'Accept': 'application/vnd.heroku+json; version=3.with-addon-billing-info'
|
23 | }}),
|
24 | api.request({
|
25 | method: 'GET',
|
26 | path: `/addons/${resolvedAddon.id}/addon-attachments`
|
27 | })
|
28 | ]
|
29 |
|
30 | addon.plan.price = grandfatheredPrice(addon)
|
31 | addon.attachments = attachments
|
32 |
|
33 | cli.styledHeader(style('addon', addon.name))
|
34 | cli.styledHash({
|
35 | Plan: addon.plan.name,
|
36 | Price: formatPrice(addon.plan.price),
|
37 | Attachments: addon.attachments.map(function (att) {
|
38 | return [
|
39 | style('app', att.app.name),
|
40 | style('attachment', att.name)
|
41 | ].join('::')
|
42 | }).sort(),
|
43 | 'Owning app': style('app', addon.app.name),
|
44 | 'Installed at': (new Date(addon.created_at)).toString(),
|
45 | 'State': formatState(addon.state)
|
46 | })
|
47 | })
|
48 | })
|
49 |
|
50 | let topic = 'addons'
|
51 | module.exports = {
|
52 | topic: topic,
|
53 | command: 'info',
|
54 | wantsApp: true,
|
55 | needsAuth: true,
|
56 | args: [{name: 'addon'}],
|
57 | run: run,
|
58 | usage: `${topic}:info ADDON`,
|
59 | description: 'Show info about an add-on and its attachments.'
|
60 | }
|