Skip to content

Commit

Permalink
refactor(index): move args array inside parseoptions function
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Jun 16, 2020
1 parent 2fca155 commit 41c44ef
Showing 1 changed file with 26 additions and 61 deletions.
87 changes: 26 additions & 61 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const platform = os.platform();
* @param {Array} args
* @returns {Promise<string|Error>} Promise of stdout string on resolve, or Error object on rejection.
*/
function parseOptions(options, acceptedOptions, args) {
function parseOptions(options, acceptedOptions) {
return new Promise((resolve, reject) => {
const args = [];
Object.keys(options).forEach((key) => {
if (Object.prototype.hasOwnProperty.call(acceptedOptions, key)) {
// eslint-disable-next-line valid-typeof
Expand Down Expand Up @@ -100,11 +101,8 @@ class Poppler {
replace: { arg: '-replace', type: 'boolean' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
args.push(fileToAttach);
args.push(outputFile);
Expand Down Expand Up @@ -169,11 +167,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);

execFile(
Expand Down Expand Up @@ -221,11 +216,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);

execFile(
Expand Down Expand Up @@ -290,11 +282,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
if (outputPrefix) {
args.push(outputPrefix);
Expand Down Expand Up @@ -371,11 +360,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);

execFile(
Expand Down Expand Up @@ -423,11 +409,8 @@ class Poppler {
printVersionInfo: { arg: '-v', type: 'boolean' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
args.push(outputPattern);

Expand Down Expand Up @@ -589,11 +572,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
if (outputFile) {
args.push(outputFile);
Expand Down Expand Up @@ -682,11 +662,8 @@ class Poppler {
zoom: { arg: '-zoom', type: 'number' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);

execFile(
Expand Down Expand Up @@ -805,11 +782,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
args.push(outputPath);

Expand Down Expand Up @@ -968,11 +942,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
args.push(outputFile);

Expand Down Expand Up @@ -1069,11 +1040,8 @@ class Poppler {
userPassword: { arg: '-upw', type: 'string' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
args.push(file);
if (outputFile) {
args.push(outputFile);
Expand Down Expand Up @@ -1116,11 +1084,8 @@ class Poppler {
printVersionInfo: { arg: '-v', type: 'boolean' }
};

// Build array of args based on options passed
const args = [];

parseOptions(options, acceptedOptions, args).then(
() => {
parseOptions(options, acceptedOptions).then(
(args) => {
files.forEach((element) => {
args.push(element);
});
Expand Down

0 comments on commit 41c44ef

Please sign in to comment.