Skip to content

Commit 2a28130

Browse files
knidarknessRomanHotsiy
authored andcommitted
feat(cli): added support for JSON string value for --options CLI argument (#1047)
closes #797
1 parent 8632b19 commit 2a28130

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cli/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ YargsParser.command(
6969
watch: argv.watch as boolean,
7070
templateFileName: argv.template as string,
7171
templateOptions: argv.templateOptions || {},
72-
redocOptions: argv.options || {},
72+
redocOptions: getObjectOrJSON(argv.options),
7373
};
7474

75+
console.log(config);
76+
7577
try {
7678
await serve(argv.port as number, argv.spec as string, config);
7779
} catch (e) {
@@ -124,7 +126,7 @@ YargsParser.command(
124126
disableGoogleFont: argv.disableGoogleFont as boolean,
125127
templateFileName: argv.template as string,
126128
templateOptions: argv.templateOptions || {},
127-
redocOptions: argv.options || {},
129+
redocOptions: getObjectOrJSON(argv.options),
128130
};
129131

130132
try {
@@ -353,3 +355,15 @@ function handleError(error: Error) {
353355
console.error(error.stack);
354356
process.exit(1);
355357
}
358+
359+
function getObjectOrJSON(options) {
360+
try {
361+
return options && typeof options === 'string'
362+
? JSON.parse(options) : options
363+
? options
364+
: {};
365+
} catch (e) {
366+
console.log(`Encountered error:\n${options}\nis not a valid JSON.`);
367+
handleError(e);
368+
}
369+
}

0 commit comments

Comments
 (0)