-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-cover-gen.mjs
executable file
·43 lines (40 loc) · 1.29 KB
/
cli-cover-gen.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
import minimist from 'minimist';
import Sunniesnow from './sunniesnow.mjs';
import CoverGen from './cover-gen.mjs';
const keys = Object.keys(CoverGen.DEFAULT_SETTINGS);
const parsedOptions = minimist(process.argv.slice(2));
const options = {};
if (parsedOptions._.length > 0) {
process.stderr.write(`Unknown options: ${parsedOptions._.join(' ')}\n`);
process.exit(1);
}
delete parsedOptions._;
for (const key of keys) {
const slugKey = Sunniesnow.Utils.camelToSlug(key);
if (Object.hasOwn(parsedOptions, slugKey)) {
options[key] = parsedOptions[slugKey];
if (typeof CoverGen.DEFAULT_SETTINGS[key] === 'number') {
options[key] = Number(options[key]);
if (isNaN(options[key])) {
process.stderr.write(`Invalid number for ${slugKey}\n`);
process.exit(1);
}
} else if (typeof CoverGen.DEFAULT_SETTINGS[key] === 'boolean') {
if (options[key] === 'true') {
options[key] = true;
} else if (options[key] === 'false') {
options[key] = false;
} else {
process.stderr.write(`Invalid boolean for ${slugKey}\n`);
process.exit(1);
}
}
delete parsedOptions[slugKey];
}
}
if (Object.keys(parsedOptions).length > 0) {
process.stderr.write(`Unknown options: ${Object.keys(parsedOptions).join(', ')}\n`);
process.exit(1);
}
await CoverGen.run(options);