@@ -2,16 +2,13 @@ package preflight
22
33import (
44 "fmt"
5- "io/ioutil"
6- "os"
75 "time"
86
97 "github.com/pkg/errors"
108 ui "github.com/replicatedhq/termui/v3"
119 "github.com/replicatedhq/termui/v3/widgets"
1210 "github.com/replicatedhq/troubleshoot/cmd/util"
1311 analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
14- "github.com/replicatedhq/troubleshoot/pkg/convert"
1512)
1613
1714var (
@@ -44,7 +41,7 @@ func showInteractiveResults(preflightName string, outputPath string, analyzeResu
4441 return nil
4542 }
4643 case "s" :
47- filename , err := save (preflightName , outputPath , analyzeResults )
44+ filename , err := outputToFile (preflightName , outputPath , analyzeResults )
4845 if err != nil {
4946 // show
5047 } else {
@@ -220,60 +217,6 @@ func estimateNumberOfLines(text string, width int) int {
220217 return lines
221218}
222219
223- func save (preflightName string , outputPath string , analyzeResults []* analyzerunner.AnalyzeResult ) (string , error ) {
224- filename := ""
225- if outputPath != "" {
226- // use override output path
227- overridePath , err := convert .ValidateOutputPath (outputPath )
228- if err != nil {
229- return "" , errors .Wrap (err , "override output file path" )
230- }
231- filename = overridePath
232- } else {
233- // use default output path
234- filename = fmt .Sprintf ("%s-results-%s.txt" , preflightName , time .Now ().Format ("2006-01-02T15_04_05" ))
235- }
236-
237- _ , err := os .Stat (filename )
238- if err == nil {
239- os .Remove (filename )
240- }
241-
242- results := fmt .Sprintf ("%s Preflight Checks\n \n " , util .AppName (preflightName ))
243- for _ , analyzeResult := range analyzeResults {
244- result := ""
245-
246- if analyzeResult .IsPass {
247- result = "Check PASS\n "
248- } else if analyzeResult .IsWarn {
249- result = "Check WARN\n "
250- } else if analyzeResult .IsFail {
251- result = "Check FAIL\n "
252- }
253-
254- result = result + fmt .Sprintf ("Title: %s\n " , analyzeResult .Title )
255- result = result + fmt .Sprintf ("Message: %s\n " , analyzeResult .Message )
256-
257- if analyzeResult .URI != "" {
258- result = result + fmt .Sprintf ("URI: %s\n " , analyzeResult .URI )
259- }
260-
261- if analyzeResult .Strict {
262- result = result + fmt .Sprintf ("Strict: %t\n " , analyzeResult .Strict )
263- }
264-
265- result = result + "\n ------------\n "
266-
267- results = results + result
268- }
269-
270- if err := ioutil .WriteFile (filename , []byte (results ), 0644 ); err != nil {
271- return "" , errors .Wrap (err , "failed to save preflight results" )
272- }
273-
274- return filename , nil
275- }
276-
277220func showSaved (filename string ) {
278221 termWidth , termHeight := ui .TerminalDimensions ()
279222
0 commit comments