Skip to content

Commit

Permalink
fix envVar option (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-codefresh authored Jul 21, 2020
1 parent e43ac4b commit e0f9e5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/interface/cli/commands/hybrid/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,22 @@ async function newAgentName(kubeContextName, kubeNamespace, agents) {

return name;
}

// eslint-disable-next-line consistent-return
function keyValueAsArrayToObject(array) {
if (array) {
const obj = {};
for (let index = 0; index < array.length; index++) {
const element = array[index];
const envVar = element.split('=');
if (envVar.length !== 2) {
throw new Error(`invalid env-var parameter ${envVar}`);
}
// eslint-disable-next-line prefer-destructuring
obj[envVar[0]] = envVar[1];
}
return obj;
}
}
function keyValueAsStringToObject(nodeSelectorStr) {
if (nodeSelectorStr) {
const kubeNodeSelectorObj = {};
Expand Down Expand Up @@ -744,6 +759,7 @@ module.exports = {
detectProxy,
serealizeToKeyValuePairs,
getRuntimeImagesWithRegistryUrl,
keyValueAsArrayToObject,
INSTALLATION_DEFAULTS,
DefaultLogFormatter,
};
3 changes: 2 additions & 1 deletion lib/interface/cli/commands/hybrid/init.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
keyValueAsStringToObject,
serealizeToKeyValuePairs,
getRuntimeImagesWithRegistryUrl,
keyValueAsArrayToObject,
INSTALLATION_DEFAULTS,
} = require('./helper');
const InstallationPlan = require('./InstallationPlan');
Expand Down Expand Up @@ -205,7 +206,7 @@ const initCmd = new Command({
} = _argv;

if (envVars) {
envVars = keyValueAsStringToObject(envVars.join(','));
envVars = keyValueAsArrayToObject(Array.isArray(envVars) ? envVars.join(',') : [envVars]);
}

if (_.get(sdk, 'config.context.isNoAuth') && !token) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.70.9",
"version": "0.71.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit e0f9e5a

Please sign in to comment.