-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
58 lines (50 loc) · 1.5 KB
/
bin.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
#!/usr/bin/env node
const server = require("./server.js") /* the current working directory so that means main.js because of package.json */
const meow = require("meow")
const myConstClass = require('./constants.js')
const cli = meow(`
Usage
$ qr-file-share
Options
--path, -p Run in given directory
--compression, -cl Compression Level when zipping directory before download
--port, -o Port to listen on
`, {
boolean: ["help", "version"],
alias: { h: "help", v: "version" },
flags: {
path: {
type: "string",
default: "",
alias: "p"
},
compression: {
type: "number",
default: myConstClass.COMPRESSION_LEVEL,
alias: "cl"
},
port: {
type: "number",
default: myConstClass.PORT,
alias: "o"
},
}
})
const path = cli.flags.path != "" ? cli.flags.path : undefined
const port = Number.isInteger(cli.flags.port) ?
cli.flags.port : undefined
const compression = Number.isInteger(cli.flags.compression) ?
cli.flags.compression : undefined
if (compression == undefined || (compression > 9 || !(compression >= 0))) {
console.log("Zip Compression Level must be a number between 0 - 9.")
quit()
}
if (port == undefined || (port > 65535 || (port <= 1023))) {
console.log("Port must be a number between 1024 - 65535.")
quit()
}
server({
base_path: path,
compression: compression,
port: port
})