Standardize CLI args

backend-refactor
Sven Slootweg 3 years ago
parent 522192f025
commit 54f178d910

@ -11,8 +11,8 @@ const chalk = require("chalk");
let argv = yargs.argv; let argv = yargs.argv;
let [ configurationPath, task, item ] = argv._; let [ configurationPath, task, item ] = argv._;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {

@ -14,8 +14,10 @@ const createKernel = require("../src/kernel");
let argv = yargs.argv; let argv = yargs.argv;
let configurationPath = argv._[0]; let configurationPath = argv._[0];
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let listenHost = argv.listenHost ?? "127.0.0.1";
let listenPort = argv.listenPort ?? 3131;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {
@ -34,5 +36,7 @@ return Promise.try(() => {
}); });
}); });
metricsApp.listen(3131); metricsApp.listen({ host: listenHost, port: listenPort }, () => {
console.log(`Metrics server listening on port ${listenPort}, host ${listenHost}`);
});
}); });

@ -21,6 +21,7 @@ const express = require("express");
const expressPromiseRouter = require("express-promise-router"); const expressPromiseRouter = require("express-promise-router");
const assert = require("assert"); const assert = require("assert");
const path = require("path"); const path = require("path");
const yargs = require("yargs");
const pipe = require("@promistream/pipe"); const pipe = require("@promistream/pipe");
const fromNodeStream = require("@promistream/from-node-stream"); const fromNodeStream = require("@promistream/from-node-stream");
@ -33,9 +34,10 @@ const isString = require("@validatem/is-string");
const initialize = require("../src/initialize"); const initialize = require("../src/initialize");
const errors = require("../src/errors"); const errors = require("../src/errors");
assert(process.argv.length >= 4); let argv = yargs.argv;
let configurationPath = process.argv[2]; let configurationPath = argv._[0];
let listenHost = process.argv[3]; let listenHost = argv.listenHost ?? "127.0.0.1";
let listenPort = argv.listenPort ?? 3000;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
@ -133,7 +135,7 @@ return Promise.try(() => {
}); });
app.use(router); app.use(router);
app.listen({ host: listenHost, port: 3000 }, () => { app.listen({ host: listenHost, port: listenPort }, () => {
console.log("Server listening on port 3000"); console.log(`API server listening on port ${listenPort}, host ${listenHost}`);
}); });
}); });

@ -11,8 +11,8 @@ const chalk = require("chalk");
let argv = yargs.argv; let argv = yargs.argv;
let [ configurationPath, task, item ] = argv._; let [ configurationPath, task, item ] = argv._;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {

@ -50,7 +50,7 @@
"pg-query-stream": "^4.1.0", "pg-query-stream": "^4.1.0",
"prom-client": "^14.0.1", "prom-client": "^14.0.1",
"syncpipe": "^1.0.0", "syncpipe": "^1.0.0",
"yargs": "^16.2.0" "yargs": "^17.3.1"
}, },
"devDependencies": { "devDependencies": {
"@joepie91/eslint-config": "^1.1.0", "@joepie91/eslint-config": "^1.1.0",

@ -3080,20 +3080,20 @@ yallist@^4.0.0:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
yargs-parser@^20.2.2: yargs-parser@^21.0.0:
version "20.2.9" version "21.0.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==
yargs@^16.2.0: yargs@^17.3.1:
version "16.2.0" version "17.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.1.tgz#da56b28f32e2fd45aefb402ed9c26f42be4c07b9"
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== integrity sha512-WUANQeVgjLbNsEmGk20f+nlHgOqzRFpiGWVaBrYGYIGANIIu3lWjoyi0fNlFmJkvfhCZ6BXINe7/W2O2bV4iaA==
dependencies: dependencies:
cliui "^7.0.2" cliui "^7.0.2"
escalade "^3.1.1" escalade "^3.1.1"
get-caller-file "^2.0.5" get-caller-file "^2.0.5"
require-directory "^2.1.1" require-directory "^2.1.1"
string-width "^4.2.0" string-width "^4.2.3"
y18n "^5.0.5" y18n "^5.0.5"
yargs-parser "^20.2.2" yargs-parser "^21.0.0"

Loading…
Cancel
Save