2014-10-29 08:02:03 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2015-01-18 08:41:37 +01:00
|
|
|
var argv = require('minimist')(process.argv.slice(2));
|
2014-10-29 08:02:03 +01:00
|
|
|
|
|
|
|
var debug = argv.debug;
|
|
|
|
delete argv.debug;
|
|
|
|
var outputFormat = argv.output;
|
|
|
|
delete argv.output;
|
|
|
|
|
|
|
|
var options = {};
|
|
|
|
for(var key in argv) {
|
|
|
|
var value = argv[key];
|
|
|
|
if(
|
|
|
|
key == '_'
|
|
|
|
|| key.charAt(0) == '$'
|
|
|
|
|| (typeof value != 'string' && typeof value != 'number')
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
options[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
var Gamedig = require('../lib/index');
|
|
|
|
if(debug) Gamedig.debug = true;
|
|
|
|
Gamedig.isCommandLine = true;
|
2017-03-14 09:40:02 +01:00
|
|
|
|
|
|
|
Gamedig.query(options)
|
|
|
|
.then((state) => {
|
2014-10-29 08:02:03 +01:00
|
|
|
if(outputFormat == 'pretty') {
|
|
|
|
console.log(JSON.stringify(state,null,' '));
|
|
|
|
} else {
|
|
|
|
console.log(JSON.stringify(state));
|
|
|
|
}
|
2017-03-14 09:40:02 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
if(outputFormat == 'pretty') {
|
|
|
|
console.log(JSON.stringify({error:error},null,' '));
|
|
|
|
} else {
|
|
|
|
console.log(JSON.stringify({error:error}));
|
|
|
|
}
|
|
|
|
});
|