From 2b05c26934624ac1e7bece9f56551e19200d21fd Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 31 Jul 2022 15:26:03 -0600 Subject: [PATCH] Disallow complex options from being set via cli Closes #2022 (wontfix) --- src/lib/utils/options/declaration.ts | 6 ++++++ src/lib/utils/options/help.ts | 2 +- src/lib/utils/options/readers/arguments.ts | 7 +++++++ src/lib/utils/options/sources/typedoc.ts | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index b87be10a5..c4e2e31aa 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -247,6 +247,12 @@ export interface DeclarationOptionBase { * If not set, the type will be a string. */ type?: ParameterType; + + /** + * If set, this option will be omitted from `--help`, and attempting to specify it on the command + * line will produce an error. + */ + configFileOnly?: boolean; } export interface StringDeclarationOption extends DeclarationOptionBase { diff --git a/src/lib/utils/options/help.ts b/src/lib/utils/options/help.ts index bad673f54..d37e336fd 100644 --- a/src/lib/utils/options/help.ts +++ b/src/lib/utils/options/help.ts @@ -40,7 +40,7 @@ function getParameterHelp(options: Options): ParameterHelp { let margin = 0; for (const parameter of parameters) { - if (!parameter.help) { + if (!parameter.help || parameter.configFileOnly) { continue; } diff --git a/src/lib/utils/options/readers/arguments.ts b/src/lib/utils/options/readers/arguments.ts index 450faa10b..a7b438987 100644 --- a/src/lib/utils/options/readers/arguments.ts +++ b/src/lib/utils/options/readers/arguments.ts @@ -48,6 +48,13 @@ export class ArgumentsReader implements OptionsReader { : options.getDeclaration("entryPoints"); if (decl) { + if (decl.configFileOnly) { + logger.error( + `The '${decl.name}' option can only be specified via a config file.` + ); + continue; + } + if (seen.has(decl.name) && ARRAY_OPTION_TYPES.has(decl.type)) { trySet( decl.name, diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index bd585036b..53d16aaca 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -37,6 +37,7 @@ export function addTypeDocOptions(options: Pick) { name: "compilerOptions", help: "Selectively override the TypeScript compiler options used by TypeDoc.", type: ParameterType.Mixed, + configFileOnly: true, validate(value) { if (!Validation.validate({}, value)) { throw new Error( @@ -191,6 +192,7 @@ export function addTypeDocOptions(options: Pick) { name: "markedOptions", help: "Specify the options passed to Marked, the Markdown parser used by TypeDoc.", type: ParameterType.Mixed, + configFileOnly: true, validate(value) { if (!Validation.validate({}, value)) { throw new Error( @@ -382,6 +384,7 @@ export function addTypeDocOptions(options: Pick) { name: "visibilityFilters", help: "Specify the default visibility for builtin filters and additional filters according to modifier tags.", type: ParameterType.Mixed, + configFileOnly: true, defaultValue: { protected: false, private: false, @@ -416,6 +419,7 @@ export function addTypeDocOptions(options: Pick) { name: "searchCategoryBoosts", help: "Configure search to give a relevance boost to selected categories", type: ParameterType.Mixed, + configFileOnly: true, defaultValue: {}, validate(value) { if (!isObject(value)) { @@ -435,6 +439,7 @@ export function addTypeDocOptions(options: Pick) { name: "searchGroupBoosts", help: 'Configure search to give a relevance boost to selected kinds (eg "class")', type: ParameterType.Mixed, + configFileOnly: true, defaultValue: {}, validate(value: unknown) { if (!isObject(value)) {