MCPcopy Index your code
hub / github.com/cameri/nostream / upsertEnvValue

Function upsertEnvValue

src/cli/utils/env-config.ts:164–181  ·  view source on GitHub ↗
(key: string, value: string)

Source from the content-addressed store, hash-verified

162}
163
164export const upsertEnvValue = (key: string, value: string): void => {
165 const envPath = getEnvFilePath()
166 const { lines, parsed } = parseEnvFile()
167
168 const existing = parsed.find((line) => line.key === key)
169 const replacement = `${key}=${value}`
170
171 if (existing) {
172 lines[existing.index] = replacement
173 } else {
174 if (lines.length > 0 && lines[lines.length - 1].trim() !== '') {
175 lines.push('')
176 }
177 lines.push(replacement)
178 }
179
180 fs.writeFileSync(envPath, lines.join('\n').replace(/\n?$/, '\n'), 'utf-8')
181}
182
183export const validateEnvValues = (values: Record<string, string>): EnvValidationIssue[] => {
184 const issues: EnvValidationIssue[] = []

Callers 1

runConfigEnvSetFunction · 0.90

Calls 2

getEnvFilePathFunction · 0.90
parseEnvFileFunction · 0.85

Tested by

no test coverage detected