Made the application cli ready
This commit is contained in:
parent
f4e1426efe
commit
fac3ddf06b
27
galaxygen
Executable file
27
galaxygen
Executable file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/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));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
|
@ -10,6 +10,9 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/96aa48/galaxygen.git"
|
"url": "git+https://github.com/96aa48/galaxygen.git"
|
||||||
},
|
},
|
||||||
|
"bin": {
|
||||||
|
"galaxygen": "galaxygen"
|
||||||
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"galaxy",
|
"galaxy",
|
||||||
"generator",
|
"generator",
|
||||||
|
@ -23,5 +26,8 @@
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/96aa48/galaxygen/issues"
|
"url": "https://github.com/96aa48/galaxygen/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/96aa48/galaxygen#readme"
|
"homepage": "https://github.com/96aa48/galaxygen#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"cli": "^0.11.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue