| 1 | package printer |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | |
| 8 | "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" |
| 9 | "review.coreboot.org/coreboot.git/util/intelp2m/logs" |
| 10 | ) |
| 11 | |
| 12 | func Do(rows []string) error { |
| 13 | path := p2m.Config.OutputPath |
| 14 | if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { |
| 15 | logs.Errorf("failed to create output directory: %v", err) |
| 16 | return err |
| 17 | } |
| 18 | |
| 19 | file, err := os.Create(path) |
| 20 | if err != nil { |
| 21 | logs.Errorf("failed to create output file: %v", err) |
| 22 | return err |
| 23 | } |
| 24 | defer file.Close() |
| 25 | |
| 26 | logs.Infof("write lines to file %s", path) |
| 27 | for i := range rows { |
| 28 | if _, err := fmt.Fprint(file, rows[i]); err != nil { |
| 29 | logs.Errorf("failed to write: %v", err) |
| 30 | return err |
| 31 | } |
| 32 | } |
| 33 | logs.Infof("successfully completed: %d rows", len(rows)) |
| 34 | return nil |
| 35 | } |