Comparing version 2.4.7 to 2.4.8
{ | ||
"name": "akkeris", | ||
"version": "2.4.7", | ||
"version": "2.4.8", | ||
"description": "Akkeris CLI", | ||
@@ -5,0 +5,0 @@ "main": "aka.js", |
@@ -45,2 +45,5 @@ "use strict" | ||
values[key] = val; | ||
if(args.unescape) { | ||
values[key] = values[key].replace(/\\n/g, '\n') | ||
} | ||
} | ||
@@ -52,3 +55,3 @@ } | ||
} | ||
appkit.api.patch(JSON.stringify(values), '/apps/' + args.app + '/config-vars', (err, config_vars) => { | ||
appkit.api.patch(JSON.stringify(values), `/apps/${args.app}/config-vars`, (err, config_vars) => { | ||
if(err) { | ||
@@ -67,3 +70,3 @@ return appkit.terminal.error(err); | ||
args['KEY'].forEach((key) => { values[key] = null; }); | ||
appkit.api.patch(JSON.stringify(values), '/apps/' + args.app + '/config-vars', (err, config_vars) => { | ||
appkit.api.patch(JSON.stringify(values), `/apps/${args.app}/config-vars`, (err, config_vars) => { | ||
if(err) { | ||
@@ -114,2 +117,9 @@ return appkit.terminal.error(err); | ||
'description':'output config vars in json format' | ||
}, | ||
'unescape':{ | ||
'alias':'u', | ||
'demand':false, | ||
'boolean':true, | ||
'default':true, | ||
'description':'Unescape new lines and other command sequences' | ||
} | ||
@@ -116,0 +126,0 @@ }; |
@@ -253,7 +253,2 @@ "use strict" | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
let scale = {}; | ||
args['TYPE=AMOUNT'].forEach((x) => { let n = x.split('='); scale[n[0]] = parseInt(n[1], 10); }); | ||
let dyno_types = Object.keys(scale); | ||
appkit.api.get('/apps/' + args.app + '/formation', (err, formations) => { | ||
@@ -266,5 +261,35 @@ if(err) { | ||
} | ||
let scale = {}; | ||
args['TYPE=AMOUNT'].forEach((x) => { | ||
if(x.indexOf('=') !== -1) { | ||
let n = x.split('='); | ||
let size = n[1].indexOf(':') === -1 ? [n[1], null] : n[1].split(':') | ||
scale[n[0]] = {"amount":parseInt(size[0], 10), "type":"equal", "size":size[1]}; | ||
} else if (x.indexOf('+') !== -1) { | ||
let n = x.split('+'); | ||
let size = n[1].indexOf(':') === -1 ? [n[1], null] : n[1].split(':') | ||
scale[n[0]] = {"amount":parseInt(size[0], 10), "type":"add", "size":size[1]}; | ||
} else if (x.indexOf('-') !== -1) { | ||
let n = x.split('-'); | ||
let size = n[1].indexOf(':') === -1 ? [n[1], null] : n[1].split(':') | ||
scale[n[0]] = {"amount":parseInt(size[0], 10), "type":"minus", "size":size[1]}; | ||
} | ||
}); | ||
let dyno_types = Object.keys(scale); | ||
for(let i=0; i < dyno_types.length; i++) { | ||
if(formations.filter((y) => { return y.type === dyno_types[i]; }).length === 0) { | ||
let current_dyno = formations.filter((y) => { return y.type === dyno_types[i]; }) | ||
if(current_dyno.length === 0) { | ||
return appkit.terminal.error({body:'{"message":"The specified dyno type ' + dyno_types[i] + ' does not exist.","code":422}',code:422}) | ||
} else if (scale[current_dyno[0].type].type === 'add') { | ||
scale[current_dyno[0].type].amount = scale[current_dyno[0].type].amount + current_dyno[0].quantity | ||
scale[current_dyno[0].type].type = 'equal' | ||
} else if (scale[current_dyno[0].type].type === 'minus') { | ||
scale[current_dyno[0].type].amount = current_dyno[0].quantity - scale[current_dyno[0].type].amount | ||
scale[current_dyno[0].type].type = 'equal' | ||
if(scale[current_dyno[0].type].amount < 0) { | ||
scale[current_dyno[0].type].amount = 0 | ||
} | ||
} | ||
@@ -275,16 +300,16 @@ } | ||
for(let i=0; i < dyno_types.length; i++) { | ||
if (args.size) { | ||
payload.push({type:dyno_types[i], quantity:scale[dyno_types[i]], size:args.size}); | ||
if (scale[dyno_types[i]].size) { | ||
payload.push({type:dyno_types[i], quantity:scale[dyno_types[i]].amount, size:scale[dyno_types[i]].size}); | ||
} else { | ||
payload.push({type:dyno_types[i], quantity:scale[dyno_types[i]].amount}); | ||
} | ||
else { | ||
payload.push({type:dyno_types[i], quantity:scale[dyno_types[i]]}); | ||
if(!(!Number.isNaN(scale[dyno_types[i]].amount) && Number.isInteger(scale[dyno_types[i]].amount) && scale[dyno_types[i]].amount > -1 && scale[dyno_types[i]].amount < 30)) { | ||
return appkit.terminal.error({body:'{"message":"Invalid quantity (' + scale[dyno_types[i]].amount + ') for dyno type ' + dyno_types[i] + '.","code":422}',code:422}); | ||
} | ||
if(!(!Number.isNaN(scale[dyno_types[i]]) && Number.isInteger(scale[dyno_types[i]]) && scale[dyno_types[i]] > -1 && scale[dyno_types[i]] < 30)) { | ||
return appkit.terminal.error({body:'{"message":"Invalid quantity for dyno type ' + dyno_types[i] + '.","code":422}',code:422}); | ||
} | ||
} | ||
let task = appkit.terminal.task(`Scaling **⬢ ${args.app}** ${args['TYPE=AMOUNT']} processes`); | ||
let string_types = Object.keys(scale).map((x) => `${x}=${scale[x].amount}${scale[x].size ? ':' + scale[x].size : ''}` ).join(', ') | ||
let task = appkit.terminal.task(`Scaling **⬢ ${args.app}** ${string_types} processes`); | ||
task.start(); | ||
appkit.api.patch(JSON.stringify(payload), '/apps/' + args.app + '/formation', (err, data) => { | ||
appkit.api.patch(JSON.stringify(payload), `/apps/${args.app}/formation`, (err, data) => { | ||
if(err) { | ||
@@ -388,2 +413,7 @@ task.end('error'); | ||
.command('ps:sizes', 'list dyno sizes',{}, list_plans.bind(null,appkit)) | ||
// aliases | ||
.command('restart [TYPE]', false, require_app_option, restart.bind(null, appkit)) | ||
.command('scale [TYPE=AMOUNT ...]', false, require_app_option, scale.bind(null, appkit)) | ||
.command('sizes', false, {}, list_plans.bind(null,appkit)) | ||
//.command('ps:resize', '', require_app_option, resize.bind(null, appkit)) | ||
@@ -390,0 +420,0 @@ //.command('ps:type [TYPE | DYNO=TYPE [DYNO=TYPE ...]]', 'manage dyno types', require_app_option, type.bind(null, appkit)) |
173042
4744
29