2014-11-24 16:12:12 +00:00
|
|
|
_ = require('lodash')
|
2014-11-26 16:15:40 +00:00
|
|
|
resin = require('../resin')
|
2014-12-05 15:51:52 +00:00
|
|
|
cli = require('../cli/cli')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui = require('../ui')
|
2014-11-24 16:12:12 +00:00
|
|
|
|
2014-11-24 16:43:37 +00:00
|
|
|
SYSTEM_VAR_REGEX = /^RESIN_/
|
|
|
|
|
|
|
|
isSystemVariable = (environmentVariable) ->
|
|
|
|
SYSTEM_VAR_REGEX.test(environmentVariable.name)
|
|
|
|
|
2014-11-27 15:22:48 +00:00
|
|
|
exports.list = ->
|
2014-12-05 15:51:52 +00:00
|
|
|
applicationId = cli.getArgument('application')
|
2014-11-24 16:12:12 +00:00
|
|
|
|
|
|
|
if not applicationId?
|
2014-11-26 16:38:02 +00:00
|
|
|
resin.errors.handle(new Error('You have to specify an application'))
|
2014-11-24 16:12:12 +00:00
|
|
|
|
2014-11-26 18:11:02 +00:00
|
|
|
resin.models.environmentVariables.getAll applicationId, (error, environmentVariables) ->
|
|
|
|
resin.errors.handle(error) if error?
|
2014-11-24 16:43:37 +00:00
|
|
|
|
2014-12-05 15:51:52 +00:00
|
|
|
if not cli.getArgument('verbose')?
|
2014-11-24 16:43:37 +00:00
|
|
|
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
|
|
|
|
2014-12-05 16:00:15 +00:00
|
|
|
resin.log.out(ui.widgets.table.horizontal(environmentVariables))
|
2014-11-24 17:00:36 +00:00
|
|
|
|
2014-11-27 15:22:48 +00:00
|
|
|
exports.remove = (id) ->
|
2014-12-05 15:51:52 +00:00
|
|
|
confirmArgument = cli.getArgument('yes')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui.patterns.remove 'environment variable', confirmArgument, (callback) ->
|
2014-11-26 18:11:02 +00:00
|
|
|
resin.models.environmentVariables.remove(id, callback)
|
2014-11-26 16:38:02 +00:00
|
|
|
, resin.errors.handle
|