(
path: string,
rawValue: string,
options: {
restart?: boolean
validate?: boolean
valueType?: ValueType
} = {},
)
| 120 | } |
| 121 | |
| 122 | export const runConfigSet = async ( |
| 123 | path: string, |
| 124 | rawValue: string, |
| 125 | options: { |
| 126 | restart?: boolean |
| 127 | validate?: boolean |
| 128 | valueType?: ValueType |
| 129 | } = {}, |
| 130 | ): Promise<number> => { |
| 131 | const valueType = options.valueType ?? 'inferred' |
| 132 | |
| 133 | const pathIssues = validatePathAgainstDefaults(path) |
| 134 | if (pathIssues.length > 0) { |
| 135 | logError(pathIssues[0].message) |
| 136 | return 1 |
| 137 | } |
| 138 | |
| 139 | const settings = loadUserSettings() as unknown as Record<string, unknown> |
| 140 | const next = setByPath(settings, path, parseTypedValue(rawValue, valueType)) |
| 141 | |
| 142 | if (options.validate !== false) { |
| 143 | const merged = loadMergedSettings() as unknown as Record<string, unknown> |
| 144 | const mergedNext = setByPath(merged, path, getByPath(next, path)) |
| 145 | const validationIssues = validateSettings(mergedNext as any) |
| 146 | |
| 147 | if (validationIssues.length > 0) { |
| 148 | logError('Config update rejected by validation:') |
| 149 | for (const issue of validationIssues) { |
| 150 | logError(`- ${issue.path}: ${issue.message}`) |
| 151 | } |
| 152 | |
| 153 | return 1 |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | saveSettings(next as any) |
| 158 | |
| 159 | logInfo(`Updated ${path}`) |
| 160 | |
| 161 | if (options.restart) { |
| 162 | return restartRelay() |
| 163 | } |
| 164 | |
| 165 | return 0 |
| 166 | } |
| 167 | |
| 168 | export const runConfigValidate = async (): Promise<number> => { |
| 169 | const settings = loadMergedSettings() |
no test coverage detected