captureOutput captures stdout during function execution
(f func())
| 776 | |
| 777 | // captureOutput captures stdout during function execution |
| 778 | func captureOutput(f func()) string { |
| 779 | old := os.Stdout |
| 780 | outFile, err := os.CreateTemp("", "codemap-cmd-output-*") |
| 781 | if err != nil { |
| 782 | panic(err) |
| 783 | } |
| 784 | defer os.Remove(outFile.Name()) |
| 785 | func() { |
| 786 | defer func() { |
| 787 | _ = outFile.Close() |
| 788 | os.Stdout = old |
| 789 | }() |
| 790 | os.Stdout = outFile |
| 791 | f() |
| 792 | }() |
| 793 | |
| 794 | data, err := os.ReadFile(outFile.Name()) |
| 795 | if err != nil { |
| 796 | panic(err) |
| 797 | } |
| 798 | return string(data) |
| 799 | } |
| 800 | |
| 801 | // writeWatchState writes a watch.State JSON file to <root>/.codemap/state.json |
| 802 | // and a PID file pointing to the current process so IsRunning returns true. |
no test coverage detected