From b9d5b0fd5962dfb8dc6692cad4a7aa518264b89b Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 24 Nov 2014 13:00:36 -0400 Subject: [PATCH] Implement env:rm command --- lib/actions/environment-variables.coffee | 9 +++++++++ lib/app.coffee | 5 +++++ lib/models/environment-variables.coffee | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/lib/actions/environment-variables.coffee b/lib/actions/environment-variables.coffee index c98a213e..74b71db3 100644 --- a/lib/actions/environment-variables.coffee +++ b/lib/actions/environment-variables.coffee @@ -1,5 +1,6 @@ _ = require('lodash') table = require('../table/table') +patterns = require('../patterns/patterns') log = require('../log/log') environemtVariablesModel = require('../models/environment-variables') authHooks = require('../hooks/auth') @@ -23,3 +24,11 @@ exports.list = authHooks.failIfNotLoggedIn (program) -> log.out(table.horizontal(environmentVariables)) .catch (error) -> throw error + +exports.remove = authHooks.failIfNotLoggedIn (id, program) -> + patterns.remove 'environment variable', program.parent.yes, (callback) -> + environemtVariablesModel.remove(id).then -> + return callback() + .catch(callback) + , (error) -> + throw error if error? diff --git a/lib/app.coffee b/lib/app.coffee index 5143b2a8..9116c370 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -122,6 +122,11 @@ program .description('List all environment variables') .action(env.list) +program + .command('env:rm ') + .description('Remove environment variable') + .action(env.remove) + data.prefix.set config.dataPrefix, (error) -> throw error if error? program.parse(process.argv) diff --git a/lib/models/environment-variables.coffee b/lib/models/environment-variables.coffee index fc158cb8..ac4feb43 100644 --- a/lib/models/environment-variables.coffee +++ b/lib/models/environment-variables.coffee @@ -13,3 +13,8 @@ exports.getAll = (applicationId) -> if not environmentVariables? return Promise.reject(new Error('Not found')) return environmentVariables + +exports.remove = (id) -> + return canvas.delete + resource: 'environment_variable' + id: id