mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 16:36:24 +00:00
Implement env add command
This commit is contained in:
parent
006f3e8aca
commit
de4c3c986e
@ -24,3 +24,18 @@ exports.remove = permissions.user (params, options) ->
|
||||
ui.patterns.remove 'environment variable', options.yes, (callback) ->
|
||||
resin.models.environmentVariables.remove(params.id, callback)
|
||||
, resin.errors.handle
|
||||
|
||||
exports.add = permissions.user (params, options) ->
|
||||
if not options.application?
|
||||
resin.errors.handle(new Error('You have to specify an application'))
|
||||
|
||||
if not params.value?
|
||||
params.value = process.env[params.key]
|
||||
|
||||
if not params.value?
|
||||
resin.errors.handle(new Error("Environment value not found for key: #{params.key}"))
|
||||
else
|
||||
resin.log.info("Warning: using #{params.key}=#{params.value} from host environment")
|
||||
|
||||
resin.models.environmentVariables.create options.application, params.key, params.value, (error) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
@ -37,6 +37,12 @@ yesOption =
|
||||
boolean: true
|
||||
alias: 'y'
|
||||
|
||||
applicationOption =
|
||||
signature: 'application'
|
||||
parameter: 'application'
|
||||
description: 'application id'
|
||||
alias: [ 'a', 'app' ]
|
||||
|
||||
# ---------- Auth Module ----------
|
||||
capitano.command
|
||||
signature: 'login [credentials]'
|
||||
@ -326,12 +332,8 @@ capitano.command
|
||||
'''
|
||||
action: actions.env.list
|
||||
options: [
|
||||
{
|
||||
signature: 'application'
|
||||
parameter: 'application'
|
||||
description: 'application id'
|
||||
alias: [ 'a', 'app' ]
|
||||
}
|
||||
applicationOption
|
||||
|
||||
{
|
||||
signature: 'verbose'
|
||||
description: 'show private environment variables'
|
||||
@ -340,6 +342,27 @@ capitano.command
|
||||
}
|
||||
]
|
||||
|
||||
capitano.command
|
||||
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: [ applicationOption ]
|
||||
action: actions.env.add
|
||||
|
||||
capitano.command
|
||||
signature: 'env rm <id>'
|
||||
description: 'remove an environment variable'
|
||||
|
@ -30,6 +30,31 @@ exports.getAllByApplication = (applicationId, callback) ->
|
||||
.catch (error) ->
|
||||
return callback(error)
|
||||
|
||||
# Create an environment variable for an application
|
||||
#
|
||||
# @param {String, Number} applicationId application id
|
||||
# @param {String} name environment variable name
|
||||
# @param {String} value environment variable value
|
||||
# @param {Function} callback callback(error)
|
||||
#
|
||||
# @example Create an environment variable
|
||||
# resin.models.environmentVariables.create 91, 'EDITOR', 'vim', (error) ->
|
||||
# throw error if error?
|
||||
#
|
||||
exports.create = (applicationId, name, value, callback) ->
|
||||
return pine.post
|
||||
resource: 'environment_variable'
|
||||
data:
|
||||
name: name
|
||||
value: value
|
||||
application: applicationId
|
||||
|
||||
.then ->
|
||||
return callback()
|
||||
|
||||
.catch (error) ->
|
||||
return callback(error)
|
||||
|
||||
# Remove environment variable
|
||||
#
|
||||
# @param {String, Number} id environment variable id
|
||||
|
Loading…
x
Reference in New Issue
Block a user