2015-01-09 15:22:18 +00:00
|
|
|
_ = require('lodash-contrib')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2015-01-21 13:50:19 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
2015-01-15 17:10:14 +00:00
|
|
|
commandOptions = require('./command-options')
|
2014-11-24 16:12:12 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
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.
|
2015-01-15 13:47:17 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
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.
|
2014-11-24 16:43:37 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Example:
|
|
|
|
$ resin envs --application 91
|
|
|
|
$ resin envs --application 91 --verbose
|
|
|
|
'''
|
|
|
|
options: [
|
|
|
|
commandOptions.application
|
2014-11-24 17:00:36 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
{
|
|
|
|
signature: 'verbose'
|
|
|
|
description: 'show private environment variables'
|
|
|
|
boolean: true
|
|
|
|
alias: 'v'
|
|
|
|
}
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-01-15 17:10:14 +00:00
|
|
|
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
|
|
|
|
return done(error) if error?
|
2014-12-19 18:07:53 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
if not options.verbose
|
|
|
|
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable)
|
2014-12-19 18:07:53 +00:00
|
|
|
|
2015-01-22 17:06:02 +00:00
|
|
|
console.log visuals.widgets.table.horizontal environmentVariables, [
|
|
|
|
'id'
|
|
|
|
'name'
|
|
|
|
'value'
|
|
|
|
]
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
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 ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-01-21 13:50:19 +00:00
|
|
|
visuals.patterns.remove 'environment variable', options.yes, (callback) ->
|
2015-01-15 17:10:14 +00:00
|
|
|
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 ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2014-12-19 18:07:53 +00:00
|
|
|
if not params.value?
|
2015-01-15 17:10:14 +00:00
|
|
|
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)
|
2014-12-19 18:07:53 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.rename =
|
|
|
|
signature: 'env rename <id> <value>'
|
|
|
|
description: 'rename an environment variable'
|
|
|
|
help: '''
|
|
|
|
Use this command to rename an enviroment variable from an application.
|
2014-12-19 18:28:03 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
|
|
|
$ resin env rename 376 emacs
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-01-15 17:10:14 +00:00
|
|
|
resin.models.environmentVariables.update(params.id, params.value, done)
|