-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
executable file
·73 lines (66 loc) · 1.57 KB
/
index.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
const info = require('./package.json');
const minimist = require('minimist');
const { uploadFiles } = require('./wormhole');
const argv = minimist(process.argv.slice(2), {
alias: {
help: 'h',
quiet: 'q',
verbose: 'v',
},
boolean: [
'help',
'quiet',
'verbose',
'version',
],
default: {
help: false,
quiet: false,
verbose: false,
version: false,
},
string: [
'chrome-args',
]
});
argv.files = argv._;
argv.chrome_args = argv['chrome-args']?.split(/\s+/);
const USAGE = [
`Usage: ${info.name} [OPTIONS] <file(s)>`,
'',
'Options:',
`\t -q --quiet Print only the download URL.`,
`\t -v --verbose Prints each step of the upload process.`,
`\t --chrome-args Arguments passed to the underlying Chromium browser.`,
`\t -h --help Prints this help text and exits.`,
`\t --version Prints the program's version and exits.`,
].join('\n')
if (argv.help) {
console.log(`${info.name} ${info.version}`);
console.log(info.description);
console.log('NOTE: This program exits only once the file upload is complete!');
console.log();
console.log(USAGE);
process.exit();
}
if (argv.version) {
console.log(info.version);
process.exit();
}
if (argv.quiet && argv.verbose) {
console.error('Error: conflicting options --quiet and --verbose given!');
console.error();
console.error(USAGE);
process.exit(1);
}
if (argv.files.length === 0) {
console.log('No files given!');
console.log(USAGE);
process.exit(1);
}
(async () => await uploadFiles(argv.files, {
chrome_args: argv.chrome_args,
quiet: argv.quiet,
verbose: argv.verbose,
}))();