balena-cli/lib/actions/environment-variables.coffee

34 lines
1.3 KiB
CoffeeScript
Raw Normal View History

_ = require('lodash-contrib')
2015-01-08 12:04:37 +00:00
resin = require('resin-sdk')
2014-12-05 16:00:15 +00:00
ui = require('../ui')
permissions = require('../permissions/permissions')
2014-11-24 16:12:12 +00:00
exports.list = permissions.user (params, options, done) ->
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
return done(error) if error?
if not options.verbose
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable)
console.log(ui.widgets.table.horizontal(environmentVariables))
return done()
2014-11-24 17:00:36 +00:00
exports.remove = permissions.user (params, options, done) ->
ui.patterns.remove 'environment variable', options.yes, (callback) ->
resin.models.environmentVariables.remove(params.id, callback)
, done
2014-12-19 18:07:53 +00:00
exports.add = permissions.user (params, options, done) ->
2014-12-19 18:07:53 +00:00
if not params.value?
params.value = process.env[params.key]
if not params.value?
return done(new Error("Environment value not found for key: #{params.key}"))
2014-12-19 18:07:53 +00:00
else
console.info("Warning: using #{params.key}=#{params.value} from host environment")
2014-12-19 18:07:53 +00:00
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
2014-12-19 18:28:03 +00:00
exports.rename = permissions.user (params, options, done) ->
resin.models.environmentVariables.update(params.id, params.value, done)