generateReport is allowed to modify p.
(p *profile.Profile, cmd []string, cfg config, o *plugin.Options)
| 112 | |
| 113 | // generateReport is allowed to modify p. |
| 114 | func generateReport(p *profile.Profile, cmd []string, cfg config, o *plugin.Options) error { |
| 115 | c, rpt, err := generateRawReport(p, cmd, cfg, o) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | // Generate the report. |
| 121 | dst := new(bytes.Buffer) |
| 122 | switch rpt.OutputFormat() { |
| 123 | case report.WebList: |
| 124 | // We need template expansion, so generate here instead of in report. |
| 125 | err = printWebList(dst, rpt, o.Obj) |
| 126 | default: |
| 127 | err = report.Generate(dst, rpt, o.Obj) |
| 128 | } |
| 129 | if err != nil { |
| 130 | return err |
| 131 | } |
| 132 | src := dst |
| 133 | |
| 134 | // If necessary, perform any data post-processing. |
| 135 | if c.postProcess != nil { |
| 136 | dst = new(bytes.Buffer) |
| 137 | if err := c.postProcess(src, dst, o.UI); err != nil { |
| 138 | return err |
| 139 | } |
| 140 | src = dst |
| 141 | } |
| 142 | |
| 143 | // If no output is specified, use default visualizer. |
| 144 | output := cfg.Output |
| 145 | if output == "" { |
| 146 | if c.visualizer != nil { |
| 147 | return c.visualizer(src, os.Stdout, o.UI) |
| 148 | } |
| 149 | _, err := src.WriteTo(os.Stdout) |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | // Output to specified file. |
| 154 | o.UI.PrintErr("Generating report in ", output) |
| 155 | out, err := o.Writer.Open(output) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | if _, err := src.WriteTo(out); err != nil { |
| 160 | out.Close() |
| 161 | return err |
| 162 | } |
| 163 | return out.Close() |
| 164 | } |
| 165 | |
| 166 | func printWebList(dst io.Writer, rpt *report.Report, obj plugin.ObjTool) error { |
| 167 | listing, err := report.MakeWebList(rpt, obj, -1) |
no test coverage detected
searching dependent graphs…