MCPcopy Create free account
hub / github.com/alibaba/open-code-review / resolveOutputWriter

Function resolveOutputWriter

cmd/opencodereview/shared.go:748–761  ·  view source on GitHub ↗

resolveOutputWriter resolves the --output target into a writer plus a cleanup function. - "" or "-" → os.Stdout with a no-op cleanup (colors preserved, no hint) - otherwise → a lazyFileWriter over a same-directory temporary file, deferred until the first Write and atomically committed by C

(path, format string)

Source from the content-addressed store, hash-verified

746// creating or truncating anything; deeper errors (permissions, disk) surface
747// on the first Write and fail the command non-zero.
748func resolveOutputWriter(path, format string) (io.Writer, func() error, error) {
749 if path == "" || path == "-" {
750 return os.Stdout, func() error { return nil }, nil
751 }
752 if st, err := os.Stat(path); err == nil && st.IsDir() {
753 return nil, nil, fmt.Errorf("--output %q is a directory", path)
754 }
755 parent := filepath.Dir(path)
756 if st, err := os.Stat(parent); err != nil || !st.IsDir() {
757 return nil, nil, fmt.Errorf("--output directory does not exist: %s", parent)
758 }
759 w := &lazyFileWriter{path: path, strip: !isMachineReadable(format)}
760 return w, w.Close, nil
761}
762
763// ResultProvider abstracts the metadata both internal/agent.Agent and
764// internal/scan.Agent expose post-run, so emitRunResult can finalize

Calls 1

isMachineReadableFunction · 0.85