({
key,
isPartOfSubgroup,
inputProps,
configMeta,
schema,
}: {
key: K;
isPartOfSubgroup: boolean;
inputProps?: InputProps<K>;
configMeta: ConfigMetadata<K>;
schema?: ZodSchema;
})
| 185 | } |
| 186 | |
| 187 | function 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 | |
| 244 | export const __testing = { _buildCommandForConfigKey }; |
no test coverage detected