mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-17 17:25:19 +01:00
1f10ad0608
* feat: add new games.extra.old_id * add extra.old_id; standard release_year * add option dontCheckOldIDs * update naming, README, CHANGELOG * Update CONTRIBUTING.md * fix games.js * add tool for checking duplicates * update GAMES_LIST * fix anchor links * fix notes in generated game list * Update GAMES_LIST.md * Update GAMES_LIST.md * add Game Object Example in CONTRIBUTING * Update find_id_duplicates.js * check skipOldIDs only once * remove old ids; tweaks GAMES_LIST * add MIGRATION document WIP * Update GAMES_LIST.md * update Halo Online name * revert changes tool/generate * remove extra line * Update GAMES_LIST.md * roll back GAME_LIST * Update GAMES_LIST.md * OMG * WAT * ok... hopefully the last change * Update GAMES_LIST.md * add MIGRATION ids * roll back CONTRIBUTING * Update CHANGELOG.md * update skipOldIDs to checkOldIDs * Update MIGRATION.md * add migration note on README
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import * as process from 'node:process'
|
|
|
|
import Minimist from 'minimist'
|
|
import { GameDig } from './../lib/index.js'
|
|
|
|
const argv = Minimist(process.argv.slice(2), {
|
|
boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules', 'requestRulesRequired', 'requestPlayersRequired', 'stripColors', 'portCache', 'noBreadthOrder', 'checkOldIDs'],
|
|
string: ['guildId', 'listenUdpPort', 'ipFamily'],
|
|
default: {
|
|
stripColors: true,
|
|
portCache: true
|
|
}
|
|
})
|
|
|
|
const options = {}
|
|
for (const key of Object.keys(argv)) {
|
|
const value = argv[key]
|
|
|
|
if (key === '_' || key.charAt(0) === '$') { continue }
|
|
|
|
options[key] = value
|
|
}
|
|
|
|
// Separate host and port
|
|
if (argv._.length >= 1) {
|
|
const target = argv._[0]
|
|
const split = target.split(':')
|
|
options.host = split[0]
|
|
if (split.length > 1) {
|
|
options.port = split[1]
|
|
}
|
|
}
|
|
|
|
const { debug, pretty } = options
|
|
|
|
const printOnPretty = (object) => {
|
|
if (!!pretty || debug) {
|
|
console.log(JSON.stringify(object, null, ' '))
|
|
} else {
|
|
console.log(JSON.stringify(object))
|
|
}
|
|
}
|
|
|
|
const gamedig = new GameDig(options)
|
|
gamedig.query(options)
|
|
.then(printOnPretty)
|
|
.catch((error) => {
|
|
if (debug) {
|
|
if (error instanceof Error) {
|
|
console.log(error.stack)
|
|
} else {
|
|
console.log(error)
|
|
}
|
|
} else {
|
|
if (error instanceof Error) {
|
|
error = error.message
|
|
}
|
|
|
|
printOnPretty({ error })
|
|
}
|
|
})
|