MCPcopy Create free account
hub / github.com/JordanCoin/codemap / captureOutput

Function captureOutput

cmd/hooks_test.go:778–799  ·  view source on GitHub ↗

captureOutput captures stdout during function execution

(f func())

Source from the content-addressed store, hash-verified

776
777// captureOutput captures stdout during function execution
778func 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.

Calls 2

RemoveMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected