mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-29 18:18:50 +00:00
116 lines
3.3 KiB
CoffeeScript
116 lines
3.3 KiB
CoffeeScript
_ = require('lodash-contrib')
|
|
resin = require('resin-sdk')
|
|
visuals = require('resin-cli-visuals')
|
|
commandOptions = require('./command-options')
|
|
|
|
exports.list =
|
|
signature: 'envs'
|
|
description: 'list all environment variables'
|
|
help: '''
|
|
Use this command to list all environment variables for a particular application.
|
|
Notice we will support per-device environment variables soon.
|
|
|
|
This command lists all custom environment variables set on the devices running
|
|
the application. If you want to see all environment variables, including private
|
|
ones used by resin, use the verbose option.
|
|
|
|
Example:
|
|
|
|
$ resin envs --application 91
|
|
$ resin envs --application 91 --verbose
|
|
'''
|
|
options: [
|
|
commandOptions.application
|
|
|
|
{
|
|
signature: 'verbose'
|
|
description: 'show private environment variables'
|
|
boolean: true
|
|
alias: 'v'
|
|
}
|
|
]
|
|
permission: 'user'
|
|
action: (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 visuals.widgets.table.horizontal environmentVariables, [
|
|
'id'
|
|
'name'
|
|
'value'
|
|
]
|
|
|
|
return done()
|
|
|
|
exports.remove =
|
|
signature: 'env rm <id>'
|
|
description: 'remove an environment variable'
|
|
help: '''
|
|
Use this command to remove an environment variable from an application.
|
|
|
|
Don't remove resin specific variables, as things might not work as expected.
|
|
|
|
Notice this command asks for confirmation interactively.
|
|
You can avoid this by passing the `--yes` boolean option.
|
|
|
|
Examples:
|
|
|
|
$ resin env rm 215
|
|
$ resin env rm 215 --yes
|
|
'''
|
|
options: [ commandOptions.yes ]
|
|
permission: 'user'
|
|
action: (params, options, done) ->
|
|
visuals.patterns.remove 'environment variable', options.yes, (callback) ->
|
|
resin.models.environmentVariables.remove(params.id, callback)
|
|
, done
|
|
|
|
exports.add =
|
|
signature: 'env add <key> [value]'
|
|
description: 'add an environment variable'
|
|
help: '''
|
|
Use this command to add an enviroment variable to an application.
|
|
|
|
You need to pass the `--application` option.
|
|
|
|
If value is omitted, the tool will attempt to use the variable's value
|
|
as defined in your host machine.
|
|
|
|
If the value is grabbed from the environment, a warning message will be printed.
|
|
Use `--quiet` to remove it.
|
|
|
|
Examples:
|
|
|
|
$ resin env add EDITOR vim -a 91
|
|
$ resin env add TERM -a 91
|
|
'''
|
|
options: [ commandOptions.application ]
|
|
permission: 'user'
|
|
action: (params, options, done) ->
|
|
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}"))
|
|
else
|
|
console.info("Warning: using #{params.key}=#{params.value} from host environment")
|
|
|
|
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
|
|
|
|
exports.rename =
|
|
signature: 'env rename <id> <value>'
|
|
description: 'rename an environment variable'
|
|
help: '''
|
|
Use this command to rename an enviroment variable from an application.
|
|
|
|
Examples:
|
|
|
|
$ resin env rename 376 emacs
|
|
'''
|
|
permission: 'user'
|
|
action: (params, options, done) ->
|
|
resin.models.environmentVariables.update(params.id, params.value, done)
|