Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added in env get, env set, and env delete.

  • Loading branch information...
commit b979ff1ed5ab34c8f965e00b974c85b5c29617aa 1 parent 32cc7c0
@mintplant authored
Showing with 84 additions and 0 deletions.
  1. +1 −0  lib/commands.js
  2. +83 −0 lib/env.js
View
1  lib/commands.js
@@ -62,6 +62,7 @@ exports.commands = {
domain: require('./appdomain'),
npm: require('./npm'),
appnpm: require('./npm'),
+ env: require('./env'),
version: {
run: function() {
log.plain(pack.version);
View
83 lib/env.js
@@ -0,0 +1,83 @@
+var node = require('nodester-api').nodester,
+ path = require('path'),
+ fs = require('fs'),
+ exists = path.existsSync,
+ config = require('./config'),
+ log = require('./log');
+
+
+module.exports = {
+ usage: function () {
+ log.usage('In a configured app dir, <appname> is optional.');
+ log.usage('env get <appname> - Gets the list of enviroment values configured for this app.');
+ log.usage('env set <appname> <key> <value> - Creates/updates an environment key/pair for this app.');
+ log.usage('env delete <appname> <key> - Deletes an environment key/value pair for this app..');
+ },
+ get: function (args) {
+ config.check();
+ var appname = config.appname;
+ if (args.length) {
+ appname = args[0].toLowerCase();
+ }
+ log.info('Gathering enviroment variables for:', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost, config.apisecure);
+ nodeapi.env_get(appname, function (err, data, original) {
+ if (err) {
+ log.error(err.message);
+ }
+ for (var x in data.message) {
+ log.info('x=', data.message[x]);
+ }
+ });
+ },
+ set: function (args) {
+ config.check();
+ var appname = config.appname,
+ p = args;
+
+ if (args.length && !appname) {
+ appname = args[0];
+ p = args.splice(1);
+ }
+ if (p.length < 2) {
+ log.error('no key/value pair to set.');
+ }
+ log.info('for app ' + appname + ', setting: ' + p[0] + '=' + p[1]);
+ var nodeapi = new node(config.username, config.password, config.apihost, config.apisecure);
+ nodeapi.env_set(appname, p[0], p[1], function (err, data, original) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info('environment variable set.');
+ } else {
+ log.warn(data.status);
+ }
+ });
+ },
+ delete: function (args) {
+ config.check();
+ var appname = config.appname,
+ p = args;
+
+ if (args.length && !appname) {
+ appname = args[0];
+ p = args.splice(1);
+ }
+ if (p.length < 1) {
+ log.error('no key to delete.');
+ }
+ log.info('for app ' + appname + ', deleting environment variable: ' + p[0]);
+ var nodeapi = new node(config.username, config.password, config.apihost, config.apisecure);
+ nodeapi.env_delete(appname, p[0], function (err, data, original) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info('environment variable deleted.');
+ } else {
+ log.warn(data.status);
+ }
+ });
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.