1 | const cli = require('heroku-cli-util')
|
2 | const co = require('co')
|
3 | const api = require('../../lib/heroku-api')
|
4 |
|
5 | function validateArgs (args) {
|
6 | if (args.length === 0) {
|
7 | cli.exit(1, 'Usage: heroku ci:config:set KEY1=VALUE1 [KEY2=VALUE2 ...]\nMust specify KEY and VALUE to set.')
|
8 | }
|
9 | }
|
10 |
|
11 | function validateInput (str) {
|
12 | if (!str.includes('=')) {
|
13 | cli.exit(1, `${cli.color.cyan(str)} is invalid. Must be in the format ${cli.color.cyan('FOO=bar')}.`)
|
14 | }
|
15 |
|
16 | return true
|
17 | }
|
18 |
|
19 | function* run (context, heroku) {
|
20 | validateArgs(context.args)
|
21 |
|
22 | const vars = context.args.reduce((memo, str) => {
|
23 | validateInput(str)
|
24 | const [key, value] = str.split('=')
|
25 | memo[key] = value
|
26 | return memo
|
27 | }, {})
|
28 |
|
29 | const coupling = yield api.pipelineCoupling(heroku, context.app)
|
30 |
|
31 | yield cli.action(
|
32 | `Setting ${Object.keys(vars).join(', ')}`,
|
33 | api.setConfigVars(heroku, coupling.pipeline.id, vars)
|
34 | )
|
35 |
|
36 | cli.styledObject(Object.keys(vars).reduce((memo, key) => {
|
37 | memo[cli.color.green(key)] = vars[key]
|
38 | return memo
|
39 | }, {}))
|
40 | }
|
41 |
|
42 | module.exports = {
|
43 | topic: 'ci',
|
44 | command: 'config:set',
|
45 | needsApp: true,
|
46 | needsAuth: true,
|
47 | variableArgs: true,
|
48 | description: 'set CI config vars',
|
49 | help: `Examples:
|
50 | $ heroku ci:config:set RAILS_ENV=test
|
51 | Setting test config vars... done
|
52 |
|
53 | RAILS_ENV: test
|
54 | `,
|
55 | run: cli.command(co.wrap(run))
|
56 | }
|