Skip to content

Commit

Permalink
do not overwrite global options (see #135)
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed Nov 9, 2024
1 parent b27dd1c commit c53b221
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
48 changes: 28 additions & 20 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function getOptions() {
return { ...options, url: positionals[0], output: positionals[1] };
}

function parseArgs(args) {
function parseArgs(args, setDefaultValues = true) {
const positionals = [];
const options = {};
const result = { positionals, options: {} };
Expand Down Expand Up @@ -246,20 +246,33 @@ function parseArgs(args) {
}
result.options[optionKey] = optionValue;
});
Object.keys(OPTIONS_INFO).forEach(optionName => {
const optionInfo = getOptionInfo(optionName);
const optionKey = getOptionKey(optionName, optionInfo);
if (result.options[optionKey] === undefined && optionInfo.defaultValue !== undefined) {
result.options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
}
});
result.options.acceptHeaders = {
font: result.options.acceptHeaderFont,
image: result.options.acceptHeaderImage,
stylesheet: result.options.acceptHeaderStylesheet,
script: result.options.acceptHeaderScript,
document: result.options.acceptHeaderDocument
};
if (setDefaultValues) {
Object.keys(OPTIONS_INFO).forEach(optionName => {
const optionInfo = getOptionInfo(optionName);
const optionKey = getOptionKey(optionName, optionInfo);
if (result.options[optionKey] === undefined && optionInfo.defaultValue !== undefined) {
result.options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
}
});
}
if (result.options.acceptHeaderFont ||
result.options.acceptHeaderImage ||
result.options.acceptHeaderStylesheet ||
result.options.acceptHeaderScript ||
result.options.acceptHeaderDocument) {
result.options.acceptHeaders = {
font: result.options.acceptHeaderFont,
image: result.options.acceptHeaderImage,
stylesheet: result.options.acceptHeaderStylesheet,
script: result.options.acceptHeaderScript,
document: result.options.acceptHeaderDocument
};
delete result.options.acceptHeaderFont;
delete result.options.acceptHeaderImage;
delete result.options.acceptHeaderStylesheet;
delete result.options.acceptHeaderScript;
delete result.options.acceptHeaderDocument;
}
if (result.options.browserArgs) {
const browserArguments = result.options.browserArguments || [];
browserArguments.push(...JSON.parse(result.options.browserArgs));
Expand Down Expand Up @@ -310,11 +323,6 @@ function parseArgs(args) {
result.options.blockedURLPatterns = result.options.blockedUrlPatterns;
delete result.options.blockedUrlPatterns;
}
delete result.options.acceptHeaderFont;
delete result.options.acceptHeaderImage;
delete result.options.acceptHeaderStylesheet;
delete result.options.acceptHeaderScript;
delete result.options.acceptHeaderDocument;
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion single-file-launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async function getUrlsFile(urlsFile) {
if (lastCharIndex < argsString.length) {
args.push(argsString.substring(lastCharIndex).trim());
}
const { options } = parseArgs(args);
const { options } = parseArgs(args, false);
return [url, options];
} else {
return value;
Expand Down

0 comments on commit c53b221

Please sign in to comment.