UNPKG

1.68 kBJavaScriptView Raw
1'use strict'
2
3let cli = require('heroku-cli-util')
4let co = require('co')
5
6function * run (context, heroku) {
7 const util = require('../../lib/util')
8
9 let app = context.app
10 let addon = yield heroku.get(`/addons/${encodeURIComponent(context.args.addon_name)}`)
11
12 function createAttachment (app, as, confirm) {
13 return cli.action(
14 `Attaching ${cli.color.addon(addon.name)}${as ? ' as ' + cli.color.attachment(as) : ''} to ${cli.color.app(app)}`,
15 heroku.request({
16 path: '/addon-attachments',
17 method: 'POST',
18 body: {
19 name: as,
20 app: {name: app},
21 addon: {name: addon.name},
22 confirm
23 }
24 })
25 )
26 }
27
28 let attachment = yield util.trapConfirmationRequired(context.app, context.flags.confirm, (confirm) => createAttachment(app, context.flags.as, confirm))
29
30 yield cli.action(
31 `Setting ${cli.color.attachment(attachment.name)} config vars and restarting ${cli.color.app(app)}`,
32 {success: false},
33 co(function * () {
34 let releases = yield heroku.get(`/apps/${app}/releases`, {
35 partial: true,
36 headers: { 'Range': 'version ..; max=1, order=desc' }
37 })
38 cli.action.done(`done, v${releases[0].version}`)
39 })
40 )
41}
42
43module.exports = {
44 topic: 'addons',
45 command: 'attach',
46 description: 'attach add-on resource to a new app',
47 needsAuth: true,
48 needsApp: true,
49 flags: [
50 {name: 'as', description: 'name for add-on attachment', hasValue: true},
51 {name: 'confirm', description: 'overwrite existing add-on attachment with same name', hasValue: true}
52 ],
53 args: [{name: 'addon_name'}],
54 run: cli.command({preauth: true}, co.wrap(run))
55}