mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-29 03:53:43 +03:00
feat(cli): added support for JSON string value for --options CLI argument (#1047)
closes #797
This commit is contained in:
parent
8632b193b2
commit
2a28130c82
18
cli/index.ts
18
cli/index.ts
|
@ -69,9 +69,11 @@ YargsParser.command(
|
||||||
watch: argv.watch as boolean,
|
watch: argv.watch as boolean,
|
||||||
templateFileName: argv.template as string,
|
templateFileName: argv.template as string,
|
||||||
templateOptions: argv.templateOptions || {},
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: getObjectOrJSON(argv.options),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await serve(argv.port as number, argv.spec as string, config);
|
await serve(argv.port as number, argv.spec as string, config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -124,7 +126,7 @@ YargsParser.command(
|
||||||
disableGoogleFont: argv.disableGoogleFont as boolean,
|
disableGoogleFont: argv.disableGoogleFont as boolean,
|
||||||
templateFileName: argv.template as string,
|
templateFileName: argv.template as string,
|
||||||
templateOptions: argv.templateOptions || {},
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: getObjectOrJSON(argv.options),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -353,3 +355,15 @@ function handleError(error: Error) {
|
||||||
console.error(error.stack);
|
console.error(error.stack);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getObjectOrJSON(options) {
|
||||||
|
try {
|
||||||
|
return options && typeof options === 'string'
|
||||||
|
? JSON.parse(options) : options
|
||||||
|
? options
|
||||||
|
: {};
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Encountered error:\n${options}\nis not a valid JSON.`);
|
||||||
|
handleError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user