mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
chore: cleaner cli (#459)
* chore: cleaner cli * chore: use destruction for argv
This commit is contained in:
parent
944716e453
commit
0a3338320e
1 changed files with 15 additions and 24 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import * as process from "node:process";
|
import * as process from 'node:process'
|
||||||
|
|
||||||
import Minimist from 'minimist'
|
import Minimist from 'minimist'
|
||||||
import { GameDig } from './../lib/index.js'
|
import { GameDig } from './../lib/index.js'
|
||||||
|
|
@ -10,17 +10,6 @@ const argv = Minimist(process.argv.slice(2), {
|
||||||
string: ['guildId', 'listenUdpPort', 'ipFamily']
|
string: ['guildId', 'listenUdpPort', 'ipFamily']
|
||||||
})
|
})
|
||||||
|
|
||||||
const debug = argv.debug
|
|
||||||
delete argv.debug
|
|
||||||
const pretty = !!argv.pretty || debug
|
|
||||||
delete argv.pretty
|
|
||||||
const givenPortOnly = argv.givenPortOnly
|
|
||||||
delete argv.givenPortOnly
|
|
||||||
const requestRulesRequired = argv.requestRulesRequired
|
|
||||||
delete argv.requestRulesRequired
|
|
||||||
const requestPlayersRequired = argv.requestPlayersRequired
|
|
||||||
delete argv.requestPlayersRequired
|
|
||||||
|
|
||||||
const options = {}
|
const options = {}
|
||||||
for (const key of Object.keys(argv)) {
|
for (const key of Object.keys(argv)) {
|
||||||
const value = argv[key]
|
const value = argv[key]
|
||||||
|
|
@ -30,6 +19,7 @@ for (const key of Object.keys(argv)) {
|
||||||
options[key] = value
|
options[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Separate host and port
|
||||||
if (argv._.length >= 1) {
|
if (argv._.length >= 1) {
|
||||||
const target = argv._[0]
|
const target = argv._[0]
|
||||||
const split = target.split(':')
|
const split = target.split(':')
|
||||||
|
|
@ -38,21 +28,22 @@ if (argv._.length >= 1) {
|
||||||
options.port = split[1]
|
options.port = split[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (debug) {
|
|
||||||
options.debug = true
|
const applyBoolean = (value, fieldName, defaultValue = true) => {
|
||||||
}
|
if (value) {
|
||||||
if (givenPortOnly) {
|
options[fieldName] = defaultValue
|
||||||
options.givenPortOnly = true
|
}
|
||||||
}
|
|
||||||
if (requestRulesRequired) {
|
|
||||||
options.requestRulesRequired = true
|
|
||||||
}
|
|
||||||
if (requestPlayersRequired) {
|
|
||||||
options.requestPlayersRequired = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { debug, pretty, givenPortOnly, requestRulesRequired, requestPlayersRequired } = argv
|
||||||
|
|
||||||
|
applyBoolean(debug, 'debug')
|
||||||
|
applyBoolean(givenPortOnly, 'givenPortOnly')
|
||||||
|
applyBoolean(requestRulesRequired, 'requestRulesRequired')
|
||||||
|
applyBoolean(requestPlayersRequired, 'requestPlayersRequired')
|
||||||
|
|
||||||
const printOnPretty = (object) => {
|
const printOnPretty = (object) => {
|
||||||
if (pretty) {
|
if (!!pretty || debug) {
|
||||||
console.log(JSON.stringify(object, null, ' '))
|
console.log(JSON.stringify(object, null, ' '))
|
||||||
} else {
|
} else {
|
||||||
console.log(JSON.stringify(object))
|
console.log(JSON.stringify(object))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue