INNER CODE UNIT · Go
emit
cli/cli · .github/skills/cli-exercise/tool/internal/preflight/main.go:76
func emit(value report, output string, streams cliutil.Streams) (int, error) {
status := value.Status
code := 2
if status == "ready" {
code = 0
} else if status == "needs-install" {
code = 1
}
if output == "" {
return code, cliutil.JSON(streams.Out, value)
}
if info, err := os.Lstat(output); err == nil && info.Mode()&os.ModeSymlink != 0 {
return 2, fmt.Errorf("report output must not replace a symbolic link")
} else if err != nil && !os.IsNotExist(err) {
return 2, err
}
if err := cliutil.WriteJSON(output, value); err != nil {
return 2, err