MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / CreateDefaultConfigFileAt

Function CreateDefaultConfigFileAt

internal/config/files.go:53–76  ·  view source on GitHub ↗

CreateDefaultConfigFileAt writes the default configuration template to the provided path. Parameters: - path: Full path where the config file should be created. This function is safe to call multiple times; if the file already exists it returns the existing path without modifying it. Example usag

(path string)

Source from the content-addressed store, hash-verified

51// log.Fatalf("create config: %v", err)
52// }
53func CreateDefaultConfigFileAt(path string) (string, error) {
54 if path == "" {
55 return "", fmt.Errorf("config path cannot be empty")
56 }
57
58 if _, err := os.Stat(path); err == nil {
59 return path, nil // File already exists
60 }
61
62 if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
63 return "", fmt.Errorf("create config directory: %w", err)
64 }
65
66 templateData, err := templateFS.ReadFile("config.tpl.yml")
67 if err != nil {
68 return "", fmt.Errorf("read template: %w", err)
69 }
70
71 if err := os.WriteFile(path, templateData, 0o600); err != nil {
72 return "", fmt.Errorf("write config file: %w", err)
73 }
74
75 return path, nil
76}
77
78// FindDefaultConfigPath finds the default configuration file path.
79func FindDefaultConfigPath() (string, bool) {

Callers 2

BootstrapFunction · 0.92
CreateDefaultConfigFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected