Skip to content

Commit

Permalink
Disallow complex options from being set via cli
Browse files Browse the repository at this point in the history
Closes #2022 (wontfix)
  • Loading branch information
Gerrit0 committed Jul 31, 2022
1 parent 04f67f0 commit 2b05c26
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib/utils/options/declaration.ts
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/options/help.ts
Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib/utils/options/readers/arguments.ts
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -37,6 +37,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
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(
Expand Down Expand Up @@ -191,6 +192,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
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(
Expand Down Expand Up @@ -382,6 +384,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
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,
Expand Down Expand Up @@ -416,6 +419,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
name: "searchCategoryBoosts",
help: "Configure search to give a relevance boost to selected categories",
type: ParameterType.Mixed,
configFileOnly: true,
defaultValue: {},
validate(value) {
if (!isObject(value)) {
Expand All @@ -435,6 +439,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
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)) {
Expand Down

0 comments on commit 2b05c26

Please sign in to comment.