Skip to content

Commit

Permalink
feat(*): allow cli args of form --arg=a in addition to --arg a
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
jbedard committed Nov 30, 2019
1 parent 7ed9ec0 commit 00a2524
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ function readVarArgs(params, i) {
return [args, i - 1];
}

function parseArgs(params) {
function parseArgs(cmdParams) {
let inputFile;
let outputFile;
let assets = [];
let rootDirs = [];

const params = cmdParams.reduce((a, p) => {
if (p.startsWith("--") && p.match(/^--[a-z]+=/)) {
a.push( ... p.split('=', 2));
} else {
a.push(p);
}
return a;
}, []);

for (let i = 0; i < params.length; i++) {
switch (params[i]) {
case "--assets":
Expand Down
15 changes: 13 additions & 2 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const {main, parseArgs} = require('../src/main');

console.log("parseArgs", parseArgs);

describe('HTML inserter', () => {
const inFile = 'data/some/index.html';
const outFile = 'out/some/index.html';
Expand Down Expand Up @@ -176,4 +174,17 @@ describe('parseArgs', () => {
expect(rootDirs).toEqual(["/c/", "/d/", "./"]);
});

it('should allow `--param=a b` in addition to `--param a b', () => {
const {outputFile, inputFile, assets, rootDirs} = parseArgs([
"--out=./out",
"--html=./in",
"--assets=./a", "./b",
"--roots=/c/", "/d/"
]);

expect(outputFile).toBe("./out");
expect(inputFile).toBe("./in");
expect(assets).toEqual(["./a", "./b"]);
expect(rootDirs).toEqual(["/c/", "/d/", "./"]);
});
});

0 comments on commit 00a2524

Please sign in to comment.