-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathset.js
More file actions
51 lines (46 loc) · 1.48 KB
/
set.js
File metadata and controls
51 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import inquirer from 'inquirer'
import reporter from '../../util/reporter'
import configSet from '../../config-set'
import * as load from '../../util/load'
import merge from 'lodash.merge'
export const command = 'set --env <env> <VARS=values...>'
export const desc = 'Set environment variables for alias on AWS'
export function builder (yargs) {
return yargs
.pkgConf('shep', process.cwd())
.boolean('quiet')
.alias('quiet', 'q')
.describe('quiet', 'Don\'t log anything')
.example('shep config set --env beta FOO=bar', 'Set environment variable FOO with value BAR for alias beta')
}
export async function handler (opts) {
const logger = opts.quiet ? () => {} : reporter()
let envVars = {}
opts.vars.forEach(function (varPair) {
const [key, value] = varPair.match(/(.*?)=(.*)/).slice(1)
envVars[key] = value
})
opts.vars = envVars
const inputs = {}
if (!opts.env) {
const envs = await load.envs()
const questions = [
{
name: 'env',
message: 'Environment',
type: 'list',
choices: () => envs
}
]
merge(inputs, await inquirer.prompt(questions))
}
logger({ type: 'start', body: 'Set environment variables on functions in AWS' })
try {
const versions = await configSet(merge({}, inputs, opts))
logger({ type: 'done' })
versions.forEach(({ FunctionName, Identifier }) => logger(`Updated ${FunctionName} to version ${Identifier.Version}`))
} catch (e) {
logger({ type: 'fail' })
throw e
}
}