MCPcopy Create free account
hub / github.com/ProspectOne/perfops-cli / OutputToFile

Function OutputToFile

cmd/internal/runtest.go:128–206  ·  view source on GitHub ↗

OutputToFile Outputs perfops response to a file or multiple files if more than one check is being ran.

(f *Formatter, output *perfops.RunOutput, fileOut string)

Source from the content-addressed store, hash-verified

126
127// OutputToFile Outputs perfops response to a file or multiple files if more than one check is being ran.
128func OutputToFile(f *Formatter, output *perfops.RunOutput, fileOut string) {
129 if f.printID {
130 f.Printf("Test ID: %v\n", output.ID)
131 }
132 spinner := f.s.Step()
133 if !output.IsFinished() {
134 f.Printf("%s", spinner)
135 if len(output.Items) > 1 {
136 finished := 0
137 for _, item := range output.Items {
138 if item.Result.IsFinished() {
139 finished++
140 }
141 }
142 f.Printf(" %d/%d", finished, len(output.Items))
143 }
144 f.Printf("\n")
145 }
146 for i, item := range output.Items {
147 r := item.Result
148 n := r.Node
149 if item.Result.Message == "" {
150 o := r.Output
151 if o == "-2" {
152 o = "The command timed-out. It either took too long to execute or we could not connect to your target at all."
153 } else if a, ok := o.([]interface{}); ok {
154 sb := strings.Builder{}
155 for _, i := range a {
156 sb.WriteString(fmt.Sprintf("%s\n", i))
157 }
158 s := sb.String()
159 o = s[:len(s)-1]
160 }
161
162 fileName := ""
163
164 if len(output.Items) > 1 {
165 fileName = formatFileName(fileOut, i)
166 } else {
167 fileName = fileOut
168 }
169
170 file, _ := os.Create(fileName)
171 defer file.Close()
172
173 w := bufio.NewWriter(file)
174
175 fmt.Fprintf(w, "Node%d, AS%d, %s, %s\n%s\n", n.ID, n.AsNumber, n.City, n.Country.Name, o)
176
177 err := w.Flush()
178
179 if err != nil {
180 return
181 }
182
183 } else if r.Message != "NO DATA" {
184 fileName := ""
185

Callers 2

runCurlFunction · 0.92
TestOutputToFileFunction · 0.85

Calls 5

formatFileNameFunction · 0.85
PrintfMethod · 0.80
StepMethod · 0.80
FlushMethod · 0.65
IsFinishedMethod · 0.45

Tested by 1

TestOutputToFileFunction · 0.68