Skip to content

Unclear Syntax for --filename-replaced-character #184

Description

@paraknell

Issue Context

Currently the help message displays the following message:

    --filename-replaced-character: 
The replaced character and the character(s) used for replacing the replacement character in filenames separated by a space, 
e.g. --filename-replaced-character ">" _GT_ to replace ">" with _GT_ <string*> (default: ["~ ~","+ +","? ?","% %","* *",": :","| |","\" "","< <","> >","\\\\ \","\\x00-\\x1f _"," _"])

Based on the presented default it would seem that a passed array should work.

(default: ["~ ~","+ +","? ?","% %","* *",": :","| |","\" "","< <","> >","\\\\ \","\\x00-\\x1f _"," _"])

And when you look at the DEFAULT_OPTIONS in it shows an array as well

$ grep -Hnri -A 15 "DEFAULT_OP"
single-file-cli-api.js-42-      filenameReplacedCharacters: ["~", "+", "?", "%", "*", ":", "|", "\"", "<", ">", "\\\\", "\x00-\x1f", "\x7F"],

If you try to set an array on the cli it will split based on the space

$ grep -Hnri -A 15 -B 5 "split(\" \""
options.js-383-         const filenameReplacedCharacters = result.options.filenameReplacedCharacters;
options.js-385-         result.options.filenameReplacedCharacters = [];
options.js-386-         result.options.filenameReplacementCharacters = [];
options.js-387-         filenameReplacedCharacters.forEach(replacement => {
options.js:388:                 let [replacedCharacter, replacementCharacter] = replacement.split(" ");

Possible Main Issue

This foreach, split and positional parameters seems to be the issue where it can't properly determine one whole string is being applied to the parameter and not to the positional argument itself.

$ npx  single-file \
--browser-executable-path "/usr/bin/chromium-browser" \
    --output-directory "./out" \
    --dump-content=false \
    --urls-file "urls.txt" \
    --filename-template="{url-href-flat}.{filename-extension}" \
    --filename-max-length "150" \
    --filename-max-length-unit "char" \
    --filename-replaced-character ": :" "| __" \
    --filename-replacement-characters "?"
[ ':' ]
:
: undefined
{
  positionals: [ '__', '--filename-replacement-characters', '?' ],

You can however set the parameter multiple times i.e.

$ npx  single-file \
<..>
    --filename-replaced-character ": :" \
  --filename-replaced-character "| __" \
<...>

Possible Solution

I am not certain if the multiple parameters is the expected method of approach, but overall this seems to increase the overhead required. I could be wrong but I would expect in most instances that the user would want to supply some list or array of characters and replace them with a single other character i.e.

--filename-replaced-character ":[]{}'|()"
--filename-replacement-character "?"

$ ls ./out
my?new?filename.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions