Skip to content

Commit deda4ce

Browse files
authored
feat: Do not prompt users to save support bundle analysis results (#1662)
In interactive mode, do not prompt users to save support bundle analysis results. Users end up providing this file instead of the support bundle archive. The analysis results are contained in the support bundle archive already Signed-off-by: Evans Mungai <[email protected]>
1 parent 350418c commit deda4ce

File tree

2 files changed

+20
-115
lines changed

2 files changed

+20
-115
lines changed

cmd/troubleshoot/cli/interactive_results.go

Lines changed: 19 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ package cli
22

33
import (
44
"fmt"
5-
"io/ioutil"
6-
"os"
7-
"path"
8-
"strings"
9-
"time"
105

116
"github.com/mitchellh/go-wordwrap"
127
"github.com/pkg/errors"
@@ -20,15 +15,14 @@ import (
2015
var (
2116
selectedResult = 0
2217
table = widgets.NewTable()
23-
isShowingSaved = false
2418
)
2519

2620
func showInteractiveResults(supportBundleName string, analyzeResults []*analyzerunner.AnalyzeResult, archivePath string) error {
2721
if err := ui.Init(); err != nil {
2822
return errors.Wrap(err, "failed to create terminal ui")
2923
}
3024
defer ui.Close()
31-
drawUI(supportBundleName, analyzeResults)
25+
drawUI(supportBundleName, analyzeResults, archivePath)
3226

3327
uiEvents := ui.PollEvents()
3428
for {
@@ -38,29 +32,10 @@ func showInteractiveResults(supportBundleName string, analyzeResults []*analyzer
3832
case "<C-c>":
3933
return nil
4034
case "q":
41-
if isShowingSaved == true {
42-
isShowingSaved = false
43-
ui.Clear()
44-
drawUI(supportBundleName, analyzeResults)
45-
} else {
46-
return nil
47-
}
48-
case "s":
49-
filename, err := save(analyzeResults)
50-
if err != nil {
51-
// show
52-
} else {
53-
showSaved(filename, archivePath)
54-
go func() {
55-
time.Sleep(time.Second * 5)
56-
isShowingSaved = false
57-
ui.Clear()
58-
drawUI(supportBundleName, analyzeResults)
59-
}()
60-
}
35+
return nil
6136
case "<Resize>":
6237
ui.Clear()
63-
drawUI(supportBundleName, analyzeResults)
38+
drawUI(supportBundleName, analyzeResults, archivePath)
6439
case "<Down>":
6540
if selectedResult < len(analyzeResults)-1 {
6641
selectedResult++
@@ -70,7 +45,7 @@ func showInteractiveResults(supportBundleName string, analyzeResults []*analyzer
7045
}
7146
table.ScrollDown()
7247
ui.Clear()
73-
drawUI(supportBundleName, analyzeResults)
48+
drawUI(supportBundleName, analyzeResults, archivePath)
7449
case "<Up>":
7550
if selectedResult > 0 {
7651
selectedResult--
@@ -80,16 +55,16 @@ func showInteractiveResults(supportBundleName string, analyzeResults []*analyzer
8055
}
8156
table.ScrollUp()
8257
ui.Clear()
83-
drawUI(supportBundleName, analyzeResults)
58+
drawUI(supportBundleName, analyzeResults, archivePath)
8459
}
8560
}
8661
}
8762
}
8863

89-
func drawUI(supportBundleName string, analyzeResults []*analyzerunner.AnalyzeResult) {
64+
func drawUI(supportBundleName string, analyzeResults []*analyzerunner.AnalyzeResult, archivePath string) {
9065
drawGrid(analyzeResults)
9166
drawHeader(supportBundleName)
92-
drawFooter()
67+
drawFooter(archivePath)
9368
}
9469

9570
func drawGrid(analyzeResults []*analyzerunner.AnalyzeResult) {
@@ -102,9 +77,7 @@ func drawHeader(supportBundleName string) {
10277

10378
title := widgets.NewParagraph()
10479
title.Text = fmt.Sprintf("%s Support Bundle Analysis", util.AppName(supportBundleName))
105-
title.TextStyle.Fg = ui.ColorWhite
106-
title.TextStyle.Bg = ui.ColorClear
107-
title.TextStyle.Modifier = ui.ModifierBold
80+
title.TextStyle = ui.NewStyle(ui.ColorWhite, ui.ColorClear, ui.ModifierBold)
10881
title.Border = false
10982

11083
left := termWidth/2 - 2*len(title.Text)/3
@@ -114,11 +87,18 @@ func drawHeader(supportBundleName string) {
11487
ui.Render(title)
11588
}
11689

117-
func drawFooter() {
90+
func drawFooter(archivePath string) {
11891
termWidth, termHeight := ui.TerminalDimensions()
11992

93+
archivePathMsg := widgets.NewParagraph()
94+
archivePathMsg.Text = "Support bundle archive: " + archivePath
95+
archivePathMsg.Border = false
96+
archivePathMsg.TextStyle = ui.NewStyle(ui.ColorWhite, ui.ColorClear, ui.ModifierBold)
97+
98+
archivePathMsg.SetRect(0, termHeight-3, termWidth, termHeight-2)
99+
120100
instructions := widgets.NewParagraph()
121-
instructions.Text = "[q] quit [s] save [↑][↓] scroll"
101+
instructions.Text = "[q] quit [↑][↓] scroll"
122102
instructions.Border = false
123103

124104
left := 0
@@ -127,13 +107,13 @@ func drawFooter() {
127107
bottom := termHeight
128108

129109
instructions.SetRect(left, top, right, bottom)
130-
ui.Render(instructions)
110+
ui.Render(archivePathMsg, instructions)
131111
}
132112

133113
func drawAnalyzersTable(analyzeResults []*analyzerunner.AnalyzeResult) {
134114
termWidth, termHeight := ui.TerminalDimensions()
135115

136-
table.SetRect(0, 3, termWidth/2, termHeight-6)
116+
table.SetRect(0, 3, termWidth/2, termHeight-4)
137117
table.FillRow = true
138118
table.Border = true
139119
table.Rows = [][]string{}
@@ -214,78 +194,3 @@ func drawDetails(analysisResult *analyzerunner.AnalyzeResult) {
214194
message.SetRect(termWidth/2, currentTop, termWidth, currentTop+height)
215195
ui.Render(message)
216196
}
217-
218-
func showSaved(filename string, archivePath string) {
219-
termWidth, termHeight := ui.TerminalDimensions()
220-
221-
f := `A support bundle was generated and saved at %s.
222-
Please send this file to your software vendor for support.`
223-
additionalMessageText := fmt.Sprintf(f, archivePath)
224-
225-
savedMessage := widgets.NewParagraph()
226-
savedMessage.Text = fmt.Sprintf("Support Bundle analysis results saved to\n\n%s\n\n%s", filename, additionalMessageText)
227-
savedMessage.WrapText = true
228-
savedMessage.Border = true
229-
230-
// Split the text into lines and find the longest line
231-
lines := strings.Split(savedMessage.Text, "\n")
232-
maxLineLength := 0
233-
for _, line := range lines {
234-
if len(line) > maxLineLength {
235-
// maxLineLength is set to half of the line length to prevent the showing text with more space than needed
236-
maxLineLength = len(line)/2 + constants.MESSAGE_TEXT_PADDING
237-
}
238-
}
239-
240-
if maxLineLength > termWidth/2 {
241-
maxLineLength = termWidth / 2
242-
}
243-
244-
left := termWidth/2 - maxLineLength
245-
right := termWidth/2 + maxLineLength
246-
top := termHeight/2 - len(lines)
247-
bottom := termHeight/2 + len(lines)
248-
249-
savedMessage.SetRect(left, top, right, bottom)
250-
ui.Render(savedMessage)
251-
252-
isShowingSaved = true
253-
}
254-
255-
func save(analyzeResults []*analyzerunner.AnalyzeResult) (string, error) {
256-
filename := path.Join(util.HomeDir(), fmt.Sprintf("%s-results.txt", "support-bundle"))
257-
_, err := os.Stat(filename)
258-
if err == nil {
259-
os.Remove(filename)
260-
}
261-
262-
results := ""
263-
for _, analyzeResult := range analyzeResults {
264-
result := ""
265-
266-
if analyzeResult.IsPass {
267-
result = "Check PASS\n"
268-
} else if analyzeResult.IsWarn {
269-
result = "Check WARN\n"
270-
} else if analyzeResult.IsFail {
271-
result = "Check FAIL\n"
272-
}
273-
274-
result = result + fmt.Sprintf("Title: %s\n", analyzeResult.Title)
275-
result = result + fmt.Sprintf("Message: %s\n", analyzeResult.Message)
276-
277-
if analyzeResult.URI != "" {
278-
result = result + fmt.Sprintf("URI: %s\n", analyzeResult.URI)
279-
}
280-
281-
result = result + "\n------------\n"
282-
283-
results = results + result
284-
}
285-
286-
if err := ioutil.WriteFile(filename, []byte(results), 0644); err != nil {
287-
return "", errors.Wrap(err, "failed to save preflight results")
288-
}
289-
290-
return filename, nil
291-
}

pkg/preflight/interactive_results.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func drawFooter() {
130130
func drawPreflightTable(analyzeResults []*analyzerunner.AnalyzeResult) {
131131
termWidth, termHeight := ui.TerminalDimensions()
132132

133-
table.SetRect(0, 3, termWidth/2, termHeight-6)
133+
table.SetRect(0, 3, termWidth/2, termHeight-4)
134134
table.FillRow = true
135135
table.Border = true
136136
table.Rows = [][]string{}

0 commit comments

Comments
 (0)