feat: Add showStackTrace CLI variable

This commit is contained in:
Joachim Van Herwegen
2021-06-07 13:36:52 +02:00
parent 57d77e941d
commit b604dd8331
13 changed files with 49 additions and 45 deletions

View File

@@ -44,41 +44,32 @@ export class AppRunner {
} = {}): void {
// Parse the command-line arguments
const { argv: params } = yargs(argv.slice(2))
.strict()
.usage('node ./bin/server.js [args]')
.check((args, options): boolean => {
// Only take flags as arguments, not filenames
if (args._ && args._.length > 0) {
throw new Error(`Unsupported arguments: ${args._.join('", "')}`);
.check((args): boolean => {
if (args._.length > 0) {
throw new Error(`Unsupported positional arguments: "${args._.join('", "')}"`);
}
for (const key in args) {
// Skip filename arguments (_) and the script name ($0)
if (key !== '_' && key !== '$0') {
// Check if the argument occurs in the provided options list
if (!options[key]) {
throw new Error(`Unknown option: "${key}"`);
}
// Check if the argument actually has a value ('> ./bin/server.js -s' is not valid)
if (!args[key]) {
throw new Error(`Missing value for argument "${key}"`);
}
// Check if the argument only has 1 value
if (Array.isArray(args[key])) {
throw new Error(`Multiple values were provided for: "${key}", [${args[key]}]`);
}
for (const key of Object.keys(args)) {
// We have no options that allow for arrays
const val = args[key];
if (key !== '_' && Array.isArray(val)) {
throw new Error(`Multiple values were provided for: "${key}": "${val.join('", "')}"`);
}
}
return true;
})
.options({
baseUrl: { type: 'string', alias: 'b' },
config: { type: 'string', alias: 'c' },
loggingLevel: { type: 'string', alias: 'l', default: 'info' },
mainModulePath: { type: 'string', alias: 'm' },
idpTemplateFolder: { type: 'string' },
port: { type: 'number', alias: 'p', default: 3000 },
rootFilePath: { type: 'string', alias: 'f', default: './' },
sparqlEndpoint: { type: 'string', alias: 's' },
podConfigJson: { type: 'string', default: './pod-config.json' },
baseUrl: { type: 'string', alias: 'b', requiresArg: true },
config: { type: 'string', alias: 'c', requiresArg: true },
loggingLevel: { type: 'string', alias: 'l', default: 'info', requiresArg: true },
mainModulePath: { type: 'string', alias: 'm', requiresArg: true },
idpTemplateFolder: { type: 'string', requiresArg: true },
port: { type: 'number', alias: 'p', default: 3000, requiresArg: true },
rootFilePath: { type: 'string', alias: 'f', default: './', requiresArg: true },
showStackTrace: { type: 'boolean', alias: 't', default: false },
sparqlEndpoint: { type: 'string', alias: 's', requiresArg: true },
podConfigJson: { type: 'string', default: './pod-config.json', requiresArg: true },
})
.help();
@@ -129,6 +120,7 @@ export class AppRunner {
'urn:solid-server:default:variable:rootFilePath':
this.resolveFilePath(params.rootFilePath),
'urn:solid-server:default:variable:sparqlEndpoint': params.sparqlEndpoint,
'urn:solid-server:default:variable:showStackTrace': params.showStackTrace,
'urn:solid-server:default:variable:podConfigJson':
this.resolveFilePath(params.podConfigJson),
'urn:solid-server:default:variable:idpTemplateFolder':
@@ -158,6 +150,7 @@ export interface ConfigVariables {
baseUrl?: string;
rootFilePath?: string;
sparqlEndpoint?: string;
showStackTrace?: boolean;
podConfigJson?: string;
idpTemplateFolder?: string;
}