UNPKG

1.87 kBJavaScriptView Raw
1'use strict'
2
3const cli = require('heroku-cli-util')
4const co = require('co')
5
6function parseConfig (args) {
7 let config = {}
8 while (args.length > 0) {
9 let key = args.shift()
10 if (!key.startsWith('--')) throw new Error(`Unexpected argument ${key}`)
11 key = key.replace(/^--/, '')
12 let val
13 if (key.includes('=')) {
14 [key, ...val] = key.split('=')
15 val = val.join('=')
16 if (val === 'true') { val = true }
17 config[key] = val
18 } else {
19 val = args.shift()
20 if (!val) {
21 config[key] = true
22 } else if (val.startsWith('--')) {
23 config[key] = true
24 args.unshift(val)
25 } else {
26 config[key] = val
27 }
28 }
29 }
30 return config
31}
32
33function * run (context, heroku) {
34 let createAddon = require('../../lib/create_addon')
35
36 let {app, flags, args} = context
37 let {name, as} = flags
38 let config = parseConfig(args.slice(1))
39
40 let addon = yield createAddon(heroku, app, args[0], context.flags.confirm, context.flags.wait, {config, name, as})
41
42 cli.log(`Use ${cli.color.cmd('heroku addons:docs ' + addon.addon_service.name)} to view documentation`)
43}
44
45const cmd = {
46 topic: 'addons',
47 description: 'create an add-on resource',
48 needsAuth: true,
49 needsApp: true,
50 args: [{name: 'service:plan'}],
51 variableArgs: true,
52 flags: [
53 {name: 'name', description: 'name for the add-on resource', hasValue: true},
54 {name: 'as', description: 'name for the initial add-on attachment', hasValue: true},
55 {name: 'confirm', description: 'overwrite existing config vars or existing add-on attachments', hasValue: true},
56 {name: 'wait', description: 'watch add-on creation status and exit when complete'}
57 ],
58 run: cli.command({preauth: true}, co.wrap(run))
59}
60
61module.exports = [
62 Object.assign({command: 'create'}, cmd),
63 Object.assign({command: 'add', hidden: true}, cmd)
64]