-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcli.js
executable file
·52 lines (47 loc) · 1.13 KB
/
cli.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
#! /usr/bin/env node
const yargs = require("yargs/yargs")
/** @type {(args:string[]) => string[]} */
// @ts-ignore
const hideBin = require("yargs/helpers").hideBin
const http = require("http")
const { setup } = require(".")
/**
* @typedef Options options
* @property {string|null} [token]
* @property {string|null} [delegates]
* @property {number} [port]
* @property {"error"|"info"|"debug"} [loglevel]
* @property {boolean} [strict]
*
* @param {Options} options
*/
const main = async ({
token = null,
delegates = null,
port = 3000,
loglevel = "info",
strict = false,
}) => {
const service = await setup({ strict, loglevel, token, delegates })
const server = http.createServer(service)
server.listen(port)
}
/** @type {import('yargs').Argv<>} */
const cli = yargs(hideBin(process.argv)).options({
port: {
type: 'number',
default: 3000,
description: 'Set port for HTTP endpoint'
},
token: {
type: 'string',
description: 'Set optional access token'
},
loglevel: {
type: 'string',
choices: ['error', 'info', 'debug'],
default: 'info',
description: 'Adjust logging'
}
})
main(cli.argv)