mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: return clear error when multiple values for a cli flag are given
* feat: return clear error when multiple values for a cli flag are given * chore: change function signature * test: add testcase for array type yargs parameter
This commit is contained in:
@@ -8,6 +8,7 @@ describe('A YargsCliExtractor', (): void => {
|
||||
const parameters: YargsParameter[] = [
|
||||
new YargsParameter('baseUrl', { alias: 'b', requiresArg: true, type: 'string' }),
|
||||
new YargsParameter('port', { alias: 'p', requiresArg: true, type: 'number' }),
|
||||
new YargsParameter('config', { alias: 'c', requiresArg: false, type: 'array' }),
|
||||
];
|
||||
let extractor: YargsCliExtractor;
|
||||
|
||||
@@ -52,6 +53,21 @@ describe('A YargsCliExtractor', (): void => {
|
||||
expect(error).toHaveBeenCalledWith('Unknown argument: unsupported');
|
||||
});
|
||||
|
||||
it('can error when multiple values are provided for a non array type parameter.', async(): Promise<void> => {
|
||||
extractor = new YargsCliExtractor(parameters, { strictMode: true });
|
||||
const argv = [ 'node', 'script', '-p', '3000', '-b', 'http://localhost:3000/', '-p', '3001' ];
|
||||
await extractor.handle(argv);
|
||||
expect(exit).toHaveBeenCalledTimes(1);
|
||||
expect(error).toHaveBeenCalledWith('Multiple values for --port (-p) were provided where only one is allowed');
|
||||
});
|
||||
|
||||
it('accepts multiple values for array type parameters.', async(): Promise<void> => {
|
||||
const argv = [ 'node', 'script', '-c', './config/a.json', '-c', './config/b.json', '-b', 'http://localhost:3000/', '-p', '3000' ];
|
||||
await expect(extractor.handle(argv)).resolves.toEqual(expect.objectContaining({
|
||||
config: [ './config/a.json', './config/b.json' ],
|
||||
}));
|
||||
});
|
||||
|
||||
it('can parse environment variables.', async(): Promise<void> => {
|
||||
// While the code below does go into the corresponding values,
|
||||
// yargs does not see the new environment variable for some reason.
|
||||
|
||||
Reference in New Issue
Block a user