MCPcopy
hub / github.com/cheat/cheat / Init

Function Init

internal/config/init.go:10–23  ·  view source on GitHub ↗

Init initializes a config file

(confpath string, configs string)

Source from the content-addressed store, hash-verified

8
9// Init initializes a config file
10func Init(confpath string, configs string) error {
11
12 // assert that the config directory exists
13 if err := os.MkdirAll(filepath.Dir(confpath), 0755); err != nil {
14 return fmt.Errorf("failed to create directory: %v", err)
15 }
16
17 // write the config file
18 if err := os.WriteFile(confpath, []byte(configs), 0644); err != nil {
19 return fmt.Errorf("failed to create file: %v", err)
20 }
21
22 return nil
23}

Callers 5

RunFunction · 0.92
TestInitFunction · 0.85
TestInitCreateDirectoryFunction · 0.85
TestInitWriteErrorFunction · 0.85
TestInitExistingFileFunction · 0.85

Calls

no outgoing calls

Tested by 4

TestInitFunction · 0.68
TestInitCreateDirectoryFunction · 0.68
TestInitWriteErrorFunction · 0.68
TestInitExistingFileFunction · 0.68