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