feat: Allow dynamically adding CLI parameters in configs

This commit is contained in:
Joachim Van Herwegen
2022-04-13 17:06:46 +02:00
parent e6519992bf
commit bedab907f9
7 changed files with 159 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import { YargsCliExtractor } from '../../../../src/init/cli/YargsCliExtractor';
const error = jest.spyOn(console, 'error').mockImplementation(jest.fn());
const log = jest.spyOn(console, 'log').mockImplementation(jest.fn());
const exit = jest.spyOn(process, 'exit').mockImplementation(jest.fn() as any);
describe('A YargsCliExtractor', (): void => {
const parameters: YargsArgOptions = {
baseUrl: { alias: 'b', requiresArg: true, type: 'string' },
@@ -41,6 +42,16 @@ describe('A YargsCliExtractor', (): void => {
await expect(extractor.handle(argv)).resolves.toEqual(expect.objectContaining({}));
});
it('combines parameters and extra parameters.', async(): Promise<void> => {
extractor = new YargsCliExtractor(parameters, {}, { test: { alias: 't', requiresArg: true, type: 'string' }});
const argv = [ 'node', 'script', '-b', 'http://localhost:3000/', '-p', '3000', '-t', 'test' ];
await expect(extractor.handle(argv)).resolves.toEqual(expect.objectContaining({
baseUrl: 'http://localhost:3000/',
port: 3000,
test: 'test',
}));
});
it('prints usage if defined.', async(): Promise<void> => {
extractor = new YargsCliExtractor(parameters, { usage: 'node ./bin/server.js [args]' });
const argv = [ 'node', 'script', '--help' ];