2014-10-29 08:02:03 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
const argv = require('minimist')(process.argv.slice(2)),
|
|
|
|
Gamedig = require('..');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
const debug = argv.debug;
|
2014-10-29 08:02:03 +01:00
|
|
|
delete argv.debug;
|
2019-01-07 07:52:29 +01:00
|
|
|
const pretty = !!argv.pretty;
|
2014-10-29 08:02:03 +01:00
|
|
|
delete argv.output;
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
const options = {};
|
|
|
|
for(const key of Object.keys(argv)) {
|
|
|
|
const value = argv[key];
|
2017-08-09 12:32:09 +02:00
|
|
|
if(
|
|
|
|
key === '_'
|
|
|
|
|| key.charAt(0) === '$'
|
|
|
|
|| (typeof value !== 'string' && typeof value !== 'number')
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
options[key] = value;
|
2014-10-29 08:02:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(debug) Gamedig.debug = true;
|
|
|
|
Gamedig.isCommandLine = true;
|
2017-03-14 09:40:02 +01:00
|
|
|
|
|
|
|
Gamedig.query(options)
|
2017-08-09 12:32:09 +02:00
|
|
|
.then((state) => {
|
2019-01-07 07:52:29 +01:00
|
|
|
if(pretty) {
|
2017-08-09 12:32:09 +02:00
|
|
|
console.log(JSON.stringify(state,null,' '));
|
|
|
|
} else {
|
|
|
|
console.log(JSON.stringify(state));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2017-08-09 11:05:55 +02:00
|
|
|
if (debug) {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
console.log(error.stack);
|
|
|
|
} else {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
error = error.message;
|
|
|
|
}
|
2019-01-07 07:52:29 +01:00
|
|
|
if (pretty) {
|
2017-08-09 11:05:55 +02:00
|
|
|
console.log(JSON.stringify({error: error}, null, ' '));
|
|
|
|
} else {
|
|
|
|
console.log(JSON.stringify({error: error}));
|
|
|
|
}
|
|
|
|
}
|
2017-08-09 12:32:09 +02:00
|
|
|
});
|