formatFile formats a single file and displays results
(filename string, timestamp string)
| 222 | |
| 223 | // formatFile formats a single file and displays results |
| 224 | func (fw *FileWatcher) formatFile(filename string, timestamp string) { |
| 225 | if fw.opts.FormatterOpts == nil { |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | formatter := NewFormatter(fw.opts.Out, fw.opts.Err, *fw.opts.FormatterOpts) |
| 230 | fileResult := formatter.formatFile(filename) |
| 231 | |
| 232 | if fileResult.Error != nil { |
| 233 | fmt.Fprintf(fw.opts.Err, "[%s] %s %s - %v\n", |
| 234 | timestamp, colorRed("✗"), filename, fileResult.Error) |
| 235 | return |
| 236 | } |
| 237 | |
| 238 | if fileResult.Changed { |
| 239 | fmt.Fprintf(fw.opts.Out, "[%s] %s %s - Formatted\n", |
| 240 | timestamp, colorGreen("✓"), filename) |
| 241 | } else { |
| 242 | fmt.Fprintf(fw.opts.Out, "[%s] %s %s - No changes needed\n", |
| 243 | timestamp, colorCyan("→"), filename) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // processAllFiles runs initial processing on all watched files |
| 248 | func (fw *FileWatcher) processAllFiles() error { |
no test coverage detected