Skip to content

Commit

Permalink
simply get JSON params from commandline
Browse files Browse the repository at this point in the history
In the previous commit regarding the params implementation (#45) on the cli, the params were a comma seperated list.
Since a FlowInstance actually supports any JSON, this is no also required for the CLI, improving flexibility.
  • Loading branch information
Stefan de Jong committed Feb 26, 2018
1 parent 89d5edb commit 07c94a8
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions bin/xible.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,6 @@ function getFlowById(flowId) {
return xible.getFlowById(flowId);
}

/**
* Parses the contents of nopt.params into an array with all parameters
* Returns null no params argument is provided on the commandline.
* @returns {String[]|null}
*/
function parseParams() {
if (!opts.params) {
return null;
}

const params = {};
opts.params.join(',').split(',').forEach((param) => {
const paramEqualsIndex = param.indexOf('=');
if (paramEqualsIndex > -1) {
const paramName = param.substring(0, paramEqualsIndex);
const paramValue = param.substring(paramEqualsIndex + 1);
params[paramName] = paramValue;
}
});
return params;
}

// cli contexts and commands
const cli = {
flow: {
Expand All @@ -166,10 +144,20 @@ const cli = {
throw `Flow "${flowName}" does not exist`;
}

let params;
if (opts.params) {
try {
params = JSON.parse(opts.params);
} catch (err) {
return Promise.reject('The provided parameters are not valid JSON');
}
}


return xible.CliQueue.add({
method: 'flow.start',
flowName,
params: parseParams()
params
});
},
async stop(flowName) {
Expand Down

0 comments on commit 07c94a8

Please sign in to comment.