(dir string, files map[string]string, force bool)
| 157 | } |
| 158 | |
| 159 | func writeFiles(dir string, files map[string]string, force bool) error { |
| 160 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 161 | return fmt.Errorf("failed to create directory: %w", err) |
| 162 | } |
| 163 | |
| 164 | for filename, content := range files { |
| 165 | path := filepath.Join(dir, filename) |
| 166 | if !force && fileExists(path) { |
| 167 | return fmt.Errorf("file %s already exists (use --force to overwrite)", path) |
| 168 | } |
| 169 | |
| 170 | if err := os.WriteFile(path, []byte(content), 0600); err != nil { |
| 171 | return fmt.Errorf("failed to write file %s: %w", filename, err) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return nil |
| 176 | } |
| 177 | |
| 178 | func fileExists(path string) bool { |
| 179 | _, err := os.Stat(path) |
no test coverage detected