mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Fix issue when there are multiple values for the same CLI parameter
* fix: added check for multiple values for the same option * Update test/unit/init/CliRunner.test.ts Co-authored-by: Ruben Verborgh <ruben@verborgh.org> * fix: made CliRunner.run sync Co-authored-by: Ruben Verborgh <ruben@verborgh.org>
This commit is contained in:
committed by
GitHub
parent
12ace1b556
commit
dd5b496f1d
@@ -13,10 +13,11 @@ export class CliRunner {
|
||||
|
||||
/**
|
||||
* Generic run function for starting the server from a given config
|
||||
* Made run to be non-async to lower the chance of unhandled promise rejection errors in the future.
|
||||
* @param args - Command line arguments.
|
||||
* @param stderr - Standard error stream.
|
||||
*/
|
||||
public async run({
|
||||
public run({
|
||||
argv = process.argv,
|
||||
stderr = process.stderr,
|
||||
}: {
|
||||
@@ -24,7 +25,7 @@ export class CliRunner {
|
||||
stdin?: ReadStream;
|
||||
stdout?: WriteStream;
|
||||
stderr?: WriteStream;
|
||||
} = {}): Promise<void> {
|
||||
} = {}): void {
|
||||
// Parse the command-line arguments
|
||||
const { argv: params } = yargs(argv.slice(2))
|
||||
.usage('node ./bin/server.js [args]')
|
||||
@@ -44,6 +45,10 @@ export class CliRunner {
|
||||
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]}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -71,7 +76,7 @@ export class CliRunner {
|
||||
const variables = this.createVariables(params);
|
||||
|
||||
// Create and execute the server initializer
|
||||
await this.createInitializer(loaderProperties, configFile, variables)
|
||||
this.createInitializer(loaderProperties, configFile, variables)
|
||||
.then(
|
||||
async(initializer): Promise<void> => initializer.handleSafe(),
|
||||
(error: Error): void => {
|
||||
|
||||
Reference in New Issue
Block a user