2016-01-04 03:58:51 +00:00
|
|
|
###
|
|
|
|
Copyright 2016 Resin.io
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
###
|
|
|
|
|
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: '''
|
2015-05-28 16:32:08 +00:00
|
|
|
Use this command to list all environment variables for
|
|
|
|
a particular application or device.
|
2015-01-15 13:47:17 +00:00
|
|
|
|
2015-05-28 16:32:08 +00:00
|
|
|
This command lists all custom environment variables.
|
|
|
|
If you want to see all environment variables, including private
|
2015-01-15 17:10:14 +00:00
|
|
|
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:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-05-28 16:32:08 +00:00
|
|
|
$ resin envs --application MyApp
|
|
|
|
$ resin envs --application MyApp --verbose
|
2016-01-21 14:23:40 +00:00
|
|
|
$ resin envs --device 7cf02a6
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
|
|
|
options: [
|
2015-05-28 16:32:08 +00:00
|
|
|
commandOptions.optionalApplication
|
|
|
|
commandOptions.optionalDevice
|
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-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
_ = require('lodash')
|
|
|
|
resin = require('resin-sdk')
|
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2015-08-17 14:32:22 +00:00
|
|
|
Promise.try ->
|
|
|
|
if options.application?
|
|
|
|
return resin.models.environmentVariables.getAllByApplication(options.application)
|
|
|
|
else if options.device?
|
|
|
|
return resin.models.environmentVariables.device.getAll(options.device)
|
|
|
|
else
|
|
|
|
throw new Error('You must specify an application or device')
|
2015-05-28 16:32:08 +00:00
|
|
|
|
2015-08-17 14:32:22 +00:00
|
|
|
.tap (environmentVariables) ->
|
2015-08-18 14:03:39 +00:00
|
|
|
if _.isEmpty(environmentVariables)
|
|
|
|
throw new Error('No environment variables found')
|
2015-08-17 14:32:22 +00:00
|
|
|
if not options.verbose
|
|
|
|
isSystemVariable = resin.models.environmentVariables.isSystemVariable
|
|
|
|
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
2015-05-28 16:32:08 +00:00
|
|
|
|
2015-08-17 14:32:22 +00:00
|
|
|
console.log visuals.table.horizontal environmentVariables, [
|
|
|
|
'id'
|
|
|
|
'name'
|
|
|
|
'value'
|
|
|
|
]
|
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2015-05-28 16:32:08 +00:00
|
|
|
If you want to eliminate a device environment variable, pass the `--device` boolean option.
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin env rm 215
|
|
|
|
$ resin env rm 215 --yes
|
2015-05-28 16:32:08 +00:00
|
|
|
$ resin env rm 215 --device
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-05-28 16:32:08 +00:00
|
|
|
options: [
|
|
|
|
commandOptions.yes
|
|
|
|
commandOptions.booleanDevice
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
resin = require('resin-sdk')
|
|
|
|
patterns = require('../utils/patterns')
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns.confirm(options.yes, 'Are you sure you want to delete the environment variable?').then ->
|
2015-08-17 14:32:22 +00:00
|
|
|
if options.device
|
|
|
|
resin.models.environmentVariables.device.remove(params.id)
|
|
|
|
else
|
|
|
|
resin.models.environmentVariables.remove(params.id)
|
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.add =
|
|
|
|
signature: 'env add <key> [value]'
|
|
|
|
description: 'add an environment variable'
|
|
|
|
help: '''
|
|
|
|
Use this command to add an enviroment variable to an application.
|
|
|
|
|
|
|
|
If value is omitted, the tool will attempt to use the variable's value
|
|
|
|
as defined in your host machine.
|
|
|
|
|
2015-05-28 16:32:08 +00:00
|
|
|
Use the `--device` option if you want to assign the environment variable
|
|
|
|
to a specific device.
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
If the value is grabbed from the environment, a warning message will be printed.
|
|
|
|
Use `--quiet` to remove it.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-05-28 16:32:08 +00:00
|
|
|
$ resin env add EDITOR vim --application MyApp
|
|
|
|
$ resin env add TERM --application MyApp
|
2016-01-21 14:23:40 +00:00
|
|
|
$ resin env add EDITOR vim --device 7cf02a6
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-05-28 16:32:08 +00:00
|
|
|
options: [
|
|
|
|
commandOptions.optionalApplication
|
|
|
|
commandOptions.optionalDevice
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
resin = require('resin-sdk')
|
|
|
|
|
2015-08-17 14:32:22 +00:00
|
|
|
Promise.try ->
|
2015-01-15 17:10:14 +00:00
|
|
|
if not params.value?
|
2015-08-17 14:32:22 +00:00
|
|
|
params.value = process.env[params.key]
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-17 14:32:22 +00:00
|
|
|
if not params.value?
|
|
|
|
throw new Error("Environment value not found for key: #{params.key}")
|
|
|
|
else
|
|
|
|
console.info("Warning: using #{params.key}=#{params.value} from host environment")
|
|
|
|
|
|
|
|
if options.application?
|
2016-02-12 18:34:16 +00:00
|
|
|
resin.models.environmentVariables.create(options.application, params.key, params.value)
|
2015-08-17 14:32:22 +00:00
|
|
|
else if options.device?
|
2016-02-12 18:34:16 +00:00
|
|
|
resin.models.environmentVariables.device.create(options.device, params.key, params.value)
|
2015-08-17 14:32:22 +00:00
|
|
|
else
|
|
|
|
throw new Error('You must specify an application or device')
|
|
|
|
.nodeify(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-05-28 16:32:08 +00:00
|
|
|
Pass the `--device` boolean option if you want to rename a device environment variable.
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin env rename 376 emacs
|
2015-05-28 16:32:08 +00:00
|
|
|
$ resin env rename 376 emacs --device
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-05-28 16:32:08 +00:00
|
|
|
options: [ commandOptions.booleanDevice ]
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
resin = require('resin-sdk')
|
|
|
|
|
2015-08-17 14:32:22 +00:00
|
|
|
Promise.try ->
|
|
|
|
if options.device
|
2016-02-12 18:34:16 +00:00
|
|
|
resin.models.environmentVariables.device.update(params.id, params.value)
|
2015-08-17 14:32:22 +00:00
|
|
|
else
|
2016-02-12 18:34:16 +00:00
|
|
|
resin.models.environmentVariables.update(params.id, params.value)
|
2015-08-17 14:32:22 +00:00
|
|
|
.nodeify(done)
|