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

Function buildInputCommand

frontend/src/ts/commandline/util.ts:187–242  ·  view source on GitHub ↗
({
  key,
  isPartOfSubgroup,
  inputProps,
  configMeta,
  schema,
}: {
  key: K;
  isPartOfSubgroup: boolean;
  inputProps?: InputProps<K>;
  configMeta: ConfigMetadata<K>;
  schema?: ZodSchema;
})

Source from the content-addressed store, hash-verified

185}
186
187function buildInputCommand<K extends keyof ConfigSchemas.Config>({
188 key,
189 isPartOfSubgroup,
190 inputProps,
191 configMeta,
192 schema,
193}: {
194 key: K;
195 isPartOfSubgroup: boolean;
196 inputProps?: InputProps<K>;
197 configMeta: ConfigMetadata<K>;
198 schema?: ZodSchema;
199}): Command {
200 const validation = inputProps?.validation ?? { schema: true };
201
202 const displayString =
203 inputProps?.display ??
204 (isPartOfSubgroup
205 ? "custom..."
206 : `${capitalizeFirstLetter(configMeta.displayString ?? key)}...`);
207
208 const result = {
209 id: `set${capitalizeFirstLetter(key)}Custom`,
210 defaultValue:
211 inputProps?.defaultValue ?? (() => Config[key]?.toString() ?? ""),
212 configValue:
213 inputProps !== undefined && "configValue" in inputProps
214 ? (inputProps.configValue ?? undefined)
215 : undefined,
216 display: displayString,
217 alias: inputProps?.alias ?? undefined,
218 input: true,
219 icon: configMeta?.fa?.icon ?? "fa-cog",
220
221 //@ts-expect-error this is fine
222 exec: ({ input }): void => {
223 if (input === undefined) return;
224 setConfig(key, input as ConfigSchemas.Config[K]);
225 inputProps?.afterExec?.(input as ConfigSchemas.Config[K]);
226 },
227 hover: inputProps?.hover,
228 };
229
230 if (inputProps?.inputValueConvert !== undefined) {
231 //@ts-expect-error this is fine
232 result["inputValueConvert"] = inputProps.inputValueConvert;
233 }
234
235 //@ts-expect-error this is fine
236 result["validation"] = {
237 schema: validation.schema === true ? schema : undefined,
238 isValid: validation.isValid,
239 };
240
241 return result as Command;
242}
243
244export const __testing = { _buildCommandForConfigKey };

Callers 1

Calls 3

capitalizeFirstLetterFunction · 0.90
setConfigFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected