UNPKG

1.93 kBJavaScriptView Raw
1'use strict'
2
3let cli = require('heroku-cli-util')
4let co = require('co')
5
6let grandfatheredPrice = require('../../lib/util').grandfatheredPrice
7let formatPrice = require('../../lib/util').formatPrice
8let formatState = require('../../lib/util').formatState
9let style = require('../../lib/util').style
10
11let 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 // the resolve call uses a variant so we cannot also use the
17 // with-addon-billing-info in the resolve call so we have to run out
18 // and grab the addon again, but can bundle with the attachments request
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
50let topic = 'addons'
51module.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}