PrintOutput prints run items that have been data.
(f *Formatter, output *perfops.RunOutput)
| 207 | |
| 208 | // PrintOutput prints run items that have been data. |
| 209 | func PrintOutput(f *Formatter, output *perfops.RunOutput) { |
| 210 | if f.printID { |
| 211 | f.Printf("Test ID: %v\n", output.ID) |
| 212 | } |
| 213 | spinner := f.s.Step() |
| 214 | if !output.IsFinished() { |
| 215 | f.Printf("%s", spinner) |
| 216 | if len(output.Items) > 1 { |
| 217 | finished := 0 |
| 218 | for _, item := range output.Items { |
| 219 | if item.Result.IsFinished() { |
| 220 | finished++ |
| 221 | } |
| 222 | } |
| 223 | f.Printf(" %d/%d", finished, len(output.Items)) |
| 224 | } |
| 225 | f.Printf("\n") |
| 226 | } |
| 227 | for _, item := range output.Items { |
| 228 | r := item.Result |
| 229 | n := r.Node |
| 230 | if item.Result.Message == "" { |
| 231 | o := r.Output |
| 232 | if o == "-2" { |
| 233 | o = "The command timed-out. It either took too long to execute or we could not connect to your target at all." |
| 234 | } else if a, ok := o.([]interface{}); ok { |
| 235 | sb := strings.Builder{} |
| 236 | for _, i := range a { |
| 237 | sb.WriteString(fmt.Sprintf("%s\n", i)) |
| 238 | } |
| 239 | s := sb.String() |
| 240 | o = s[:len(s)-1] |
| 241 | } |
| 242 | if len(output.Items) > 1 { |
| 243 | fmt.Println("Greater Than One") |
| 244 | } |
| 245 | f.Printf("Node%d, AS%d, %s, %s\n%s\n", n.ID, n.AsNumber, n.City, n.Country.Name, o) |
| 246 | } else if r.Message != "NO DATA" { |
| 247 | f.Printf("Node%d, AS%d, %s, %s\n%s\n", n.ID, n.AsNumber, n.City, n.Country.Name, r.Message) |
| 248 | } |
| 249 | if !item.Result.IsFinished() { |
| 250 | f.Printf("%s\n", spinner) |
| 251 | } |
| 252 | } |
| 253 | f.Flush(!output.IsFinished()) |
| 254 | } |
| 255 | |
| 256 | // PrintOutputJSON marshals the output into JSON and prints the JSON. |
| 257 | func PrintOutputJSON(output interface{}) error { |