cmdline: add arguments

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2019-01-12 13:54:30 +08:00
parent 29f8158821
commit 26c79d54e5
3 changed files with 21 additions and 7 deletions

View File

@ -6,6 +6,7 @@ const url = require('url');
const mkdirp = require('mkdirp');
const socket_io = require('socket.io');
const crypto = require('crypto');
const program = require('commander');
const app = express();
const port = 9119;
@ -13,14 +14,21 @@ const port = 9119;
const server = http.createServer(app);
const io = socket_io(server);
program
.version('1.0')
.option('-s, --secret <s>', 'Secret from Git Webhook')
.option('-p, --port <n>', 'Port to listen to', parseInt)
.option('-r, --repo-root <root>', 'Root for repo and web stuff')
.option('-m, --repo-prefix <prefix>', 'Add a URI to an allowed repo prefix', (val, memo) => { memo.push(val) }, [])
.parse(process.argv);
const default_prefixes = process.env['RV_PREFIXES'] ? process.env['RV_PREFIXES'].split(',') : [ 'https://git.xobs.io/xobs' ];
const config = {
secret: '1234',
port: 9119,
addr: '0.0.0.0',
repo_root: 'repo-root',
repo_prefixes: [
'https://git.xobs.io/xobs'
]
secret: program.secret || process.env['RV_SECRET'] || '1234',
port: program.port || process.env['RV_LISTEN_PORT'] || 9119,
addr: process.env['RV_LISTEN_ADDR'] || '0.0.0.0',
repo_root: program.repoRoot || process.env['RV_ROOT'] || 'repo-root',
repo_prefixes: program.repoPrefix.length ? program.repoPrefix : default_prefixes
};
function update_repo(repo) {

5
package-lock.json generated
View File

@ -247,6 +247,11 @@
"delayed-stream": "~1.0.0"
}
},
"commander": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz",
"integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg=="
},
"component-bind": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",

View File

@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"commander": "^2.19.0",
"express": "^4.16.4",
"mkdirp": "^0.5.1",
"nodegit": "^0.23.0",