This repository has been archived on 2024-02-25. You can view files and clone it, but cannot push or open issues or pull requests.
galaxygen/galaxygen
2016-06-28 21:38:41 +02:00

28 lines
817 B
JavaScript
Executable file

#!/bin/env node
const fs = require('fs');
const cli = require('cli');
const galaxy = require('./index');
cli.parse({
seed: ['s', 'The seed you want to generate with. (defaults to \'1234\')', 'string'],
amount: ['a', 'The amount of stars you want to generate. (defaults to 1000)', 'int'],
output: ['o', 'The output file (if enabled). (defaults to printing JSON to stdout)', 'string'],
});
cli.main((args, options) => {
var gen = galaxy.generate(options.seed, options.amount);
if (options.output) {
fs.access(options.output, fs.R_OK | fs.W_OK, (err) => {
if (err) console.log('No write access to the specified output file!');
else {
fs.writeFileSync(options.output, JSON.stringify(gen, null, 2));
}
});
}
else {
console.log(JSON.stringify(gen, null, 2));
}
});