@@ -4,14 +4,14 @@ import (
44 "fmt"
55 "io/ioutil"
66 "os"
7- "path"
87 "time"
98
109 "github.com/pkg/errors"
1110 ui "github.com/replicatedhq/termui/v3"
1211 "github.com/replicatedhq/termui/v3/widgets"
1312 "github.com/replicatedhq/troubleshoot/cmd/util"
1413 analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
14+ "github.com/replicatedhq/troubleshoot/pkg/convert"
1515)
1616
1717var (
2020 isShowingSaved = false
2121)
2222
23- func showInteractiveResults (preflightName string , analyzeResults []* analyzerunner.AnalyzeResult ) error {
23+ func showInteractiveResults (preflightName string , outputPath string , analyzeResults []* analyzerunner.AnalyzeResult ) error {
2424 if err := ui .Init (); err != nil {
2525 return errors .Wrap (err , "failed to create terminal ui" )
2626 }
@@ -44,7 +44,7 @@ func showInteractiveResults(preflightName string, analyzeResults []*analyzerunne
4444 return nil
4545 }
4646 case "s" :
47- filename , err := save (preflightName , analyzeResults )
47+ filename , err := save (preflightName , outputPath , analyzeResults )
4848 if err != nil {
4949 // show
5050 } else {
@@ -217,8 +217,20 @@ func estimateNumberOfLines(text string, width int) int {
217217 return lines
218218}
219219
220- func save (preflightName string , analyzeResults []* analyzerunner.AnalyzeResult ) (string , error ) {
221- filename := path .Join (util .HomeDir (), fmt .Sprintf ("%s-results.txt" , preflightName ))
220+ func save (preflightName string , outputPath string , analyzeResults []* analyzerunner.AnalyzeResult ) (string , error ) {
221+ filename := ""
222+ if outputPath != "" {
223+ // use override output path
224+ overridePath , err := convert .ValidateOutputPath (outputPath )
225+ if err != nil {
226+ return "" , errors .Wrap (err , "override output file path" )
227+ }
228+ filename = overridePath
229+ } else {
230+ // use default output path
231+ filename = fmt .Sprintf ("%s-results-%s.txt" , preflightName , time .Now ().Format ("2006-01-02T15_04_05" ))
232+ }
233+
222234 _ , err := os .Stat (filename )
223235 if err == nil {
224236 os .Remove (filename )
0 commit comments