MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / buildCommandWithSubgroup

Function buildCommandWithSubgroup

frontend/src/ts/commandline/util.ts:84–133  ·  view source on GitHub ↗
(
  key: K,
  rootDisplay: string | undefined,
  rootAlias: string | undefined,
  subgroupProps: SubgroupProps<K>,
  configMeta: ConfigMetadata<K>,
  schema: ZodSchema,
)

Source from the content-addressed store, hash-verified

82}
83
84function buildCommandWithSubgroup<K extends keyof ConfigSchemas.Config>(
85 key: K,
86 rootDisplay: string | undefined,
87 rootAlias: string | undefined,
88 subgroupProps: SubgroupProps<K>,
89 configMeta: ConfigMetadata<K>,
90 schema: ZodSchema,
91): Command {
92 if (subgroupProps === null) {
93 throw new Error(`No commandline metadata found for config key "${key}".`);
94 }
95
96 const display =
97 rootDisplay ??
98 `${capitalizeFirstLetter(configMeta?.displayString ?? key)}...`;
99
100 let values =
101 subgroupProps.options ?? (getOptions(schema) as ConfigSchemas.Config[K][]);
102
103 if (values === "fromSchema") {
104 values = getOptions(schema) as ConfigSchemas.Config[K][];
105 }
106
107 if (values === undefined) {
108 throw new Error(
109 `Unsupported schema type for key "${key}": ${(schema as ZodFirstPartySchemaTypes)._def.typeName}`,
110 );
111 }
112 const list = values.map((value) =>
113 buildSubgroupCommand<K>(key, value, subgroupProps),
114 );
115
116 list.sort((a, b) => {
117 if (a.configValue === "off" || a.configValue === false) return -1;
118 if (b.configValue === "off" || b.configValue === false) return 1;
119 return 0;
120 });
121
122 return {
123 id: `change${capitalizeFirstLetter(key)}`,
124 display: display,
125 icon: configMeta?.fa?.icon ?? "fa-cog",
126 subgroup: {
127 title: display,
128 configKey: key,
129 list,
130 },
131 alias: rootAlias,
132 };
133}
134
135function buildSubgroupCommand<K extends keyof ConfigSchemas.Config>(
136 key: keyof ConfigSchemas.Config,

Callers 1

Calls 3

capitalizeFirstLetterFunction · 0.90
getOptionsFunction · 0.90
buildSubgroupCommandFunction · 0.85

Tested by

no test coverage detected