21 lines
928 B
JavaScript
21 lines
928 B
JavaScript
const DEFAULTS = { server: null, user: null, folder: null, out: 'odt' }
|
|
|
|
// Reads the command line of the download helper. Same shape as the importer's
|
|
// own parser: anything unexpected is reported, never ignored.
|
|
export function parseFetchArguments(argv) {
|
|
const options = { ...DEFAULTS, problems: [] }
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const name = argv[index].startsWith('--') ? argv[index].slice(2) : ''
|
|
if (!Object.hasOwn(DEFAULTS, name)) {
|
|
options.problems.push(`unknown argument: ${argv[index]}`)
|
|
// Skip what looked like its value, so a mistyped flag is reported once.
|
|
if (name !== '' && !(argv[index + 1] ?? '--').startsWith('--')) index += 1
|
|
continue
|
|
}
|
|
index += 1
|
|
const value = argv[index]
|
|
if (value === undefined || value.startsWith('--')) options.problems.push(`--${name} needs a value`)
|
|
else options[name] = value
|
|
}
|
|
return options
|
|
}
|