forked from fastify/fastify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.js
70 lines (66 loc) · 1.98 KB
/
args.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
'use strict'
const argv = require('yargs-parser')
module.exports = function parseArgs (args) {
const parsedArgs = argv(args, {
configuration: {
'populate--': true
},
number: ['port', 'inspect-port', 'body-limit', 'plugin-timeout'],
string: ['log-level', 'address', 'socket', 'prefix', 'ignore-watch', 'logging-module', 'debug-host', 'lang', 'require'],
boolean: ['pretty-logs', 'options', 'watch', 'verbose-watch', 'debug'],
envPrefix: 'FASTIFY_',
alias: {
port: ['p'],
socket: ['s'],
help: ['h'],
options: ['o'],
address: ['a'],
watch: ['w'],
prefix: ['x'],
require: ['r'],
debug: ['d'],
'debug-port': ['I'],
'log-level': ['l'],
'pretty-logs': ['P'],
'plugin-timeout': ['T'],
'logging-module': ['L']
},
default: {
'log-level': 'fatal',
'pretty-logs': false,
watch: false,
verboseWatch: false,
debug: false,
debugPort: 9320,
'ignore-watch': 'node_modules build dist .git bower_components logs .swp .nyc_output',
options: false,
'plugin-timeout': 10 * 1000, // everything should load in 10 seconds
lang: 'js'
}
})
const additionalArgs = parsedArgs['--'] || []
const { _, ...pluginOptions } = argv(additionalArgs)
return {
_: parsedArgs._,
'--': additionalArgs,
port: parsedArgs.port,
bodyLimit: parsedArgs.bodyLimit,
pluginTimeout: parsedArgs.pluginTimeout,
pluginOptions,
prettyLogs: parsedArgs.prettyLogs,
options: parsedArgs.options,
watch: parsedArgs.watch,
debug: parsedArgs.debug,
debugPort: parsedArgs.debugPort,
debugHost: parsedArgs.debugHost,
ignoreWatch: parsedArgs.ignoreWatch,
verboseWatch: parsedArgs.verboseWatch,
logLevel: parsedArgs.logLevel,
address: parsedArgs.address,
socket: parsedArgs.socket,
require: parsedArgs.require,
prefix: parsedArgs.prefix,
loggingModule: parsedArgs.loggingModule,
lang: parsedArgs.lang
}
}