MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / writeConfigFile

Function writeConfigFile

internal/tools/configwriter.go:180–206  ·  view source on GitHub ↗
(path, format string, data map[string]any)

Source from the content-addressed store, hash-verified

178}
179
180func writeConfigFile(path, format string, data map[string]any) error {
181 if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
182 return fmt.Errorf("configwriter: mkdir %s: %w", filepath.Dir(path), err)
183 }
184 var encoded []byte
185 var err error
186 switch format {
187 case "json":
188 encoded, err = json.MarshalIndent(data, "", " ")
189 if err == nil {
190 encoded = append(encoded, '\n')
191 }
192 case "toml":
193 encoded, err = tomlv2.Marshal(data)
194 case "yaml":
195 encoded, err = yaml.Marshal(data)
196 default:
197 return fmt.Errorf("configwriter: unknown format %q", format)
198 }
199 if err != nil {
200 return fmt.Errorf("configwriter: marshal %s: %w", path, err)
201 }
202 if err := os.WriteFile(path, encoded, 0o600); err != nil {
203 return fmt.Errorf("configwriter: write %s: %w", path, err)
204 }
205 return nil
206}

Callers 2

ApplyFunction · 0.70
applyCodexWireAPIFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected