CLI for parse-live-query-server (#2765)
* adds CLI for parse-live-query-server, adds ability to start parse-server with live-query server * Don't crash when the message is badly formatted
This commit is contained in:
59
src/cli/utils/parsers.js
Normal file
59
src/cli/utils/parsers.js
Normal file
@@ -0,0 +1,59 @@
|
||||
export function numberParser(key) {
|
||||
return function(opt) {
|
||||
opt = parseInt(opt);
|
||||
if (!Number.isInteger(opt)) {
|
||||
throw new Error(`The ${key} is invalid`);
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
|
||||
export function numberOrBoolParser(key) {
|
||||
return function(opt) {
|
||||
if (typeof opt === 'boolean') {
|
||||
return opt;
|
||||
}
|
||||
return numberParser(key)(opt);
|
||||
}
|
||||
}
|
||||
|
||||
export function objectParser(opt) {
|
||||
if (typeof opt == 'object') {
|
||||
return opt;
|
||||
}
|
||||
return JSON.parse(opt)
|
||||
}
|
||||
|
||||
export function arrayParser(opt) {
|
||||
if (Array.isArray(opt)) {
|
||||
return opt;
|
||||
} else if (typeof opt === 'string') {
|
||||
return opt.split(',');
|
||||
} else {
|
||||
throw new Error(`${opt} should be a comma separated string or an array`);
|
||||
}
|
||||
}
|
||||
|
||||
export function moduleOrObjectParser(opt) {
|
||||
if (typeof opt == 'object') {
|
||||
return opt;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(opt);
|
||||
} catch(e) {}
|
||||
return opt;
|
||||
}
|
||||
|
||||
export function booleanParser(opt) {
|
||||
if (opt == true || opt == "true" || opt == "1") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function nullParser(opt) {
|
||||
if (opt == 'null') {
|
||||
return null;
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
37
src/cli/utils/runner.js
Normal file
37
src/cli/utils/runner.js
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
import program from './commander';
|
||||
import { mergeWithOptions } from './commander';
|
||||
|
||||
function logStartupOptions(options) {
|
||||
for (let key in options) {
|
||||
let value = options[key];
|
||||
if (key == "masterKey") {
|
||||
value = "***REDACTED***";
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
console.log(`${key}: ${value}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default function({
|
||||
definitions,
|
||||
help,
|
||||
usage,
|
||||
start
|
||||
}) {
|
||||
program.loadDefinitions(definitions);
|
||||
if (usage) {
|
||||
program.usage(usage);
|
||||
}
|
||||
if (help) {
|
||||
program.on('--help', help);
|
||||
}
|
||||
program.parse(process.argv, process.env);
|
||||
|
||||
let options = program.getOptions();
|
||||
start(program, options, function() {
|
||||
logStartupOptions(options);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user