(
key: K,
configMeta: ConfigMetadata<K>,
commandMeta:
| CommandlineConfigMetadata<K, keyof ConfigSchemas.Config>
| undefined,
schema: ZodSchema,
)
| 24 | return _buildCommandForConfigKey(key, configMeta, commandMeta, schema); |
| 25 | } |
| 26 | function _buildCommandForConfigKey< |
| 27 | K extends keyof CommandlineConfigMetadataObject, |
| 28 | >( |
| 29 | key: K, |
| 30 | configMeta: ConfigMetadata<K>, |
| 31 | commandMeta: |
| 32 | | CommandlineConfigMetadata<K, keyof ConfigSchemas.Config> |
| 33 | | undefined, |
| 34 | schema: ZodSchema, |
| 35 | ): Command { |
| 36 | if (commandMeta === undefined || commandMeta === null) { |
| 37 | throw new Error(`No commandline metadata found for config key "${key}".`); |
| 38 | } |
| 39 | |
| 40 | let result: Command | undefined = undefined; |
| 41 | |
| 42 | if ("subgroup" in commandMeta && commandMeta.subgroup !== undefined) { |
| 43 | result = buildCommandWithSubgroup( |
| 44 | key, |
| 45 | commandMeta.display, |
| 46 | commandMeta.alias, |
| 47 | commandMeta.subgroup, |
| 48 | configMeta, |
| 49 | schema, |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | if ("input" in commandMeta && commandMeta.input !== undefined) { |
| 54 | const inputProps = commandMeta.input; |
| 55 | |
| 56 | const inputCommand = buildInputCommand({ |
| 57 | key: "secondKey" in inputProps ? inputProps.secondKey : key, |
| 58 | isPartOfSubgroup: "subgroup" in commandMeta, |
| 59 | inputProps: inputProps as InputProps<keyof ConfigSchemas.Config>, |
| 60 | configMeta: configMeta as unknown as ConfigMetadata< |
| 61 | keyof ConfigSchemas.Config |
| 62 | >, |
| 63 | schema: |
| 64 | "secondKey" in inputProps |
| 65 | ? ConfigSchemas.ConfigSchema.shape[inputProps.secondKey] |
| 66 | : schema, |
| 67 | }); |
| 68 | |
| 69 | if (result === undefined) { |
| 70 | return inputCommand; |
| 71 | } |
| 72 | |
| 73 | result.subgroup?.list.push(inputCommand); |
| 74 | } |
| 75 | |
| 76 | if (result === undefined) { |
| 77 | throw new Error( |
| 78 | `Nothing returned for config key "${key}". This is a bug in the commandline metadata.`, |
| 79 | ); |
| 80 | } |
| 81 | return result; |
| 82 | } |
| 83 |
no test coverage detected