Skip to content

Commit

Permalink
add toCliString function fixes #140 (#312)
Browse files Browse the repository at this point in the history
* add toCliString function fixes #140

Signed-off-by: tech4GT <[email protected]>

* update docs

Signed-off-by: tech4GT <[email protected]>

* add test

Signed-off-by: tech4GT <[email protected]>
  • Loading branch information
tech4GT authored and jywarren committed Aug 4, 2018
1 parent 5ab018f commit 5b4e904
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ But for this, double quotes must wrap the space-separated steps.

Options for the steps can be passed in one line as json in the details option like
```
$ ./index.js -i [PATH] -s "brightness" -d '{"brightness":50}'
$ ./index.js -i [PATH] -s "brightness" -c '{"brightness":50}'
```
Or the values can be given through terminal prompt like
Expand Down
29 changes: 22 additions & 7 deletions dist/image-sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47793,6 +47793,20 @@ ImageSequencer = function ImageSequencer(options) {
return modulesdata;
}

// Genates a CLI string for the current sequence
function toCliString() {
var cliStringSteps = `"`, cliOptions = {};
for (var step in this.steps) {
if (this.steps[step].options.name !== "load-image")
cliStringSteps += `${this.steps[step].options.name} `;
for (var inp in modulesInfo(this.steps[step].options.name).inputs) {
cliOptions[inp] = this.steps[step].options[inp];
}
}
cliStringSteps = cliStringSteps.substr(0, cliStringSteps.length - 1) + `"`;
return `sequencer -i [PATH] -s ${cliStringSteps} -d '${JSON.stringify(cliOptions)}'`
}

// Strigifies the current sequence
function toString(step) {
if (step) {
Expand Down Expand Up @@ -47977,6 +47991,7 @@ ImageSequencer = function ImageSequencer(options) {
setUI: setUI,
exportBin: exportBin,
modulesInfo: modulesInfo,
toCliString: toCliString,
toString: toString,
stepToString: stepToString,
toJSON: toJSON,
Expand Down Expand Up @@ -48651,29 +48666,29 @@ module.exports={
/*
* Display only one color channel
*/
module.exports = function Channel(options,UI) {
module.exports = function Channel(options, UI) {

options.channel = options.channel || "green";

var output;

function draw(input,callback,progressObj) {
function draw(input, callback, progressObj) {

progressObj.stop(true);
progressObj.overrideFlag = true;

var step = this;

function changePixel(r, g, b, a) {
if (options.channel == "red") return [r, 0, 0, a];
if (options.channel == "red") return [r, 0, 0, a];
if (options.channel == "green") return [0, g, 0, a];
if (options.channel == "blue") return [0, 0, b, a];
if (options.channel == "blue") return [0, 0, b, a];
}

function output(image,datauri,mimetype){
function output(image, datauri, mimetype) {

// This output is accesible by Image Sequencer
step.output = {src:datauri,format:mimetype};
step.output = { src: datauri, format: mimetype };

}

Expand All @@ -48691,7 +48706,7 @@ module.exports = function Channel(options,UI) {
return {
options: options,
//setup: setup, // optional
draw: draw,
draw: draw,
output: output,
UI: UI
}
Expand Down
2 changes: 1 addition & 1 deletion dist/image-sequencer.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ if (program.saveSequence) {

if (program.config) {
try {
program.config = JSON.parse(program.config);
console.log(`The parsed options object: `, program.config);
var config = JSON.parse(program.config);
console.log(`The parsed options object: `, config);
} catch (e) {
console.error(
"\x1b[31m%s\x1b[0m",
Expand All @@ -121,10 +121,10 @@ if (program.saveSequence) {
console.log(e);
}
}
if (program.config && validateConfig(program.config, options)) {
if (program.config && validateConfig(config, options)) {
console.log("Now using Options object");
Object.keys(options).forEach(function(input) {
options[input] = program.config[input];
options[input] = config[input];
});
} else {
// If inputs exist, iterate through them and prompt for values.
Expand Down
15 changes: 15 additions & 0 deletions src/ImageSequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ ImageSequencer = function ImageSequencer(options) {
return modulesdata;
}

// Genates a CLI string for the current sequence
function toCliString() {
var cliStringSteps = `"`, cliOptions = {};
for (var step in this.steps) {
if (this.steps[step].options.name !== "load-image")
cliStringSteps += `${this.steps[step].options.name} `;
for (var inp in modulesInfo(this.steps[step].options.name).inputs) {
cliOptions[inp] = this.steps[step].options[inp];
}
}
cliStringSteps = cliStringSteps.substr(0, cliStringSteps.length - 1) + `"`;
return `sequencer -i [PATH] -s ${cliStringSteps} -d '${JSON.stringify(cliOptions)}'`
}

// Strigifies the current sequence
function toString(step) {
if (step) {
Expand Down Expand Up @@ -415,6 +429,7 @@ ImageSequencer = function ImageSequencer(options) {
setUI: setUI,
exportBin: exportBin,
modulesInfo: modulesInfo,
toCliString: toCliString,
toString: toString,
stepToString: stepToString,
toJSON: toJSON,
Expand Down
14 changes: 7 additions & 7 deletions src/modules/Channel/Module.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
* Display only one color channel
*/
module.exports = function Channel(options,UI) {
module.exports = function Channel(options, UI) {

options.channel = options.channel || "green";

var output;

function draw(input,callback,progressObj) {
function draw(input, callback, progressObj) {

progressObj.stop(true);
progressObj.overrideFlag = true;

var step = this;

function changePixel(r, g, b, a) {
if (options.channel == "red") return [r, 0, 0, a];
if (options.channel == "red") return [r, 0, 0, a];
if (options.channel == "green") return [0, g, 0, a];
if (options.channel == "blue") return [0, 0, b, a];
if (options.channel == "blue") return [0, 0, b, a];
}

function output(image,datauri,mimetype){
function output(image, datauri, mimetype) {

// This output is accesible by Image Sequencer
step.output = {src:datauri,format:mimetype};
step.output = { src: datauri, format: mimetype };

}

Expand All @@ -41,7 +41,7 @@ module.exports = function Channel(options,UI) {
return {
options: options,
//setup: setup, // optional
draw: draw,
draw: draw,
output: output,
UI: UI
}
Expand Down
Loading

0 comments on commit 5b4e904

Please sign in to comment.