@@ -2,11 +2,6 @@ package cli
2
2
3
3
import (
4
4
"fmt"
5
- "io/ioutil"
6
- "os"
7
- "path"
8
- "strings"
9
- "time"
10
5
11
6
"github.com/mitchellh/go-wordwrap"
12
7
"github.com/pkg/errors"
@@ -20,15 +15,14 @@ import (
20
15
var (
21
16
selectedResult = 0
22
17
table = widgets .NewTable ()
23
- isShowingSaved = false
24
18
)
25
19
26
20
func showInteractiveResults (supportBundleName string , analyzeResults []* analyzerunner.AnalyzeResult , archivePath string ) error {
27
21
if err := ui .Init (); err != nil {
28
22
return errors .Wrap (err , "failed to create terminal ui" )
29
23
}
30
24
defer ui .Close ()
31
- drawUI (supportBundleName , analyzeResults )
25
+ drawUI (supportBundleName , analyzeResults , archivePath )
32
26
33
27
uiEvents := ui .PollEvents ()
34
28
for {
@@ -38,29 +32,10 @@ func showInteractiveResults(supportBundleName string, analyzeResults []*analyzer
38
32
case "<C-c>" :
39
33
return nil
40
34
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
61
36
case "<Resize>" :
62
37
ui .Clear ()
63
- drawUI (supportBundleName , analyzeResults )
38
+ drawUI (supportBundleName , analyzeResults , archivePath )
64
39
case "<Down>" :
65
40
if selectedResult < len (analyzeResults )- 1 {
66
41
selectedResult ++
@@ -70,7 +45,7 @@ func showInteractiveResults(supportBundleName string, analyzeResults []*analyzer
70
45
}
71
46
table .ScrollDown ()
72
47
ui .Clear ()
73
- drawUI (supportBundleName , analyzeResults )
48
+ drawUI (supportBundleName , analyzeResults , archivePath )
74
49
case "<Up>" :
75
50
if selectedResult > 0 {
76
51
selectedResult --
@@ -80,16 +55,16 @@ func showInteractiveResults(supportBundleName string, analyzeResults []*analyzer
80
55
}
81
56
table .ScrollUp ()
82
57
ui .Clear ()
83
- drawUI (supportBundleName , analyzeResults )
58
+ drawUI (supportBundleName , analyzeResults , archivePath )
84
59
}
85
60
}
86
61
}
87
62
}
88
63
89
- func drawUI (supportBundleName string , analyzeResults []* analyzerunner.AnalyzeResult ) {
64
+ func drawUI (supportBundleName string , analyzeResults []* analyzerunner.AnalyzeResult , archivePath string ) {
90
65
drawGrid (analyzeResults )
91
66
drawHeader (supportBundleName )
92
- drawFooter ()
67
+ drawFooter (archivePath )
93
68
}
94
69
95
70
func drawGrid (analyzeResults []* analyzerunner.AnalyzeResult ) {
@@ -102,9 +77,7 @@ func drawHeader(supportBundleName string) {
102
77
103
78
title := widgets .NewParagraph ()
104
79
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 )
108
81
title .Border = false
109
82
110
83
left := termWidth / 2 - 2 * len (title .Text )/ 3
@@ -114,11 +87,18 @@ func drawHeader(supportBundleName string) {
114
87
ui .Render (title )
115
88
}
116
89
117
- func drawFooter () {
90
+ func drawFooter (archivePath string ) {
118
91
termWidth , termHeight := ui .TerminalDimensions ()
119
92
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
+
120
100
instructions := widgets .NewParagraph ()
121
- instructions .Text = "[q] quit [s] save [ ↑][↓] scroll"
101
+ instructions .Text = "[q] quit [↑][↓] scroll"
122
102
instructions .Border = false
123
103
124
104
left := 0
@@ -127,13 +107,13 @@ func drawFooter() {
127
107
bottom := termHeight
128
108
129
109
instructions .SetRect (left , top , right , bottom )
130
- ui .Render (instructions )
110
+ ui .Render (archivePathMsg , instructions )
131
111
}
132
112
133
113
func drawAnalyzersTable (analyzeResults []* analyzerunner.AnalyzeResult ) {
134
114
termWidth , termHeight := ui .TerminalDimensions ()
135
115
136
- table .SetRect (0 , 3 , termWidth / 2 , termHeight - 6 )
116
+ table .SetRect (0 , 3 , termWidth / 2 , termHeight - 4 )
137
117
table .FillRow = true
138
118
table .Border = true
139
119
table .Rows = [][]string {}
@@ -214,78 +194,3 @@ func drawDetails(analysisResult *analyzerunner.AnalyzeResult) {
214
194
message .SetRect (termWidth / 2 , currentTop , termWidth , currentTop + height )
215
195
ui .Render (message )
216
196
}
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
- }
0 commit comments