Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes error on | character in CLI #1634

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ else if (program.installModule) installModule(program, sequencer);
else {
// Parse step into an array to allow for multiple steps.
if (!program.step) exit('No steps passed');

program.steps = sequencer.stringToJSON(program.step);

var stepNames = [];
program.step.split(',').forEach(v => stepNames.push(v.split('{')[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use array map function.
stepNames = program.step.split(',').map(....).

Let's make the code concise and modern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea you're right, I will do that ASAP!


program.step = program.step.split(' ');

// User must input an image.
Expand All @@ -44,7 +50,7 @@ else {
});

// User must input a step. If steps exist, check that every step is a valid step.
if (!program.step || !(utils.validateSteps(program.step, sequencer)))
if (!program.steps || !(utils.validateSteps(program.steps, sequencer)))
exit('Please ensure all steps are valid.');

// If there's no user defined output directory, select a default directory.
Expand All @@ -57,7 +63,7 @@ else {
step.info = sequencer.modulesInfo(step.name);

for (var output in step.info.outputs) {
console.log('[' + program.step + ']: ' + output + ' = ' + step[output]);
console.log('[' + stepNames + ']: ' + output + ' = ' + step[output]);
}
},
notify: function(msg) {
Expand Down
3 changes: 2 additions & 1 deletion src/CliUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ function validateSteps(steps, sequencer) {
// Assume all are valid in the beginning.
var valid = true;
steps.forEach(function(step) {
console.log(step.name);
jywarren marked this conversation as resolved.
Show resolved Hide resolved
// If any step in the array is not valid (not a property of modulesInfo), set valid to false.
if (!sequencer.modulesInfo().hasOwnProperty(step)) {
if (!sequencer.modulesInfo().hasOwnProperty(step.name)) {
valid = false;
}
});
Expand Down
29 changes: 8 additions & 21 deletions src/cli/sequencerSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,31 @@ module.exports = function (program, sequencer, outputFilename) {
if (program.basic)
console.log('Basic mode is enabled, outputting only final image');

// Iterate through the steps and retrieve their inputs.
program.step.forEach(function(step) {
var options = Object.assign({}, sequencer.modulesInfo(step).inputs);

program.steps.forEach(function(step) {
var options = Object.assign({}, sequencer.modulesInfo(step.name).inputs);

// If inputs exists, print to console.
if (Object.keys(options).length) {
console.log('[' + step + ']: Inputs');
console.log('[' + step.name + ']: Inputs');
}

// If inputs exists, print them out with descriptions.
Object.keys(options).forEach(function(input) {
// The array below creates a variable number of spaces. This is done with (length + 1).
// The extra 4 that makes it (length + 5) is to account for the []: characters
console.log(
new Array(step.length + 5).join(' ') +
new Array(step.name.length + 5).join(' ') +
input +
': ' +
options[input].desc
);
});

if (program.config) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this and why was it removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used to get input for options for different modules using -c flag, I removed this to support new format.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can't directly give input? Or is there a different flag for it now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah just need clarification on this - thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:
./index.js -s "webgl-distort" -c '{"nw":"100,100","se":"40,40"}' -i examples/images/test.png
Now:
./index.js -s "webgl-distort{nw:100%2C100|se:40%2C40}" -i examples/images/test.png

So since we used to give options seperately therefore we needed the -c flag but now the option values are given inside the same string(just like the url) so it isn't needed anymore.

try {
var config = JSON.parse(program.config);
console.log('The parsed options object: ', config);
} catch (e) {
console.error(
'\x1b[31m%s\x1b[0m',
'Options(Config) is not a not valid JSON Fallback activate'
);
program.config = false;
console.log(e);
}
}
if (program.config && utils.validateConfig(config, options)) {
if (Object.keys(step.options).length > 0) {
console.log('Now using Options object');
Object.keys(options).forEach(function(input) {
options[input] = config[input];
options[input] = step.options[input];
});
} else {
// If inputs exist, iterate through them and prompt for values.
Expand All @@ -66,7 +53,7 @@ module.exports = function (program, sequencer, outputFilename) {
});
}
// Add the step and its inputs to the sequencer.
sequencer.addSteps(step, options);
sequencer.addSteps(step.name, options);
});

var spinnerObj = { succeed: () => { }, stop: () => { } };
Expand Down