-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_ascii.go
70 lines (59 loc) · 1.52 KB
/
report_ascii.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package drivercaps
import (
"bufio"
"io"
"log"
"os"
"time"
"github.com/olekukonko/tablewriter"
)
func renderASCII(results [][]string, test *DriverTest, tim time.Time) {
writeASCII(os.Stdout, results, test, tim)
}
func writeASCIIFile(results [][]string, test *DriverTest, tim time.Time) {
filename := localFilename(asciiFilename)
// log.Println("filename", filename)
f, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
bufw := bufio.NewWriter(f)
writeASCII(bufw, results, test, tim)
bufw.Flush()
}
func writeASCII(w io.Writer, results [][]string, test *DriverTest, tim time.Time) {
header := []string{
"DDL Definition",
".Name",
".DBTypeName",
".Nullable",
".DecimalSize",
".Length",
".ScanType",
}
table := tablewriter.NewWriter(w)
// table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(false)
// table.SetHeader(results[0])
table.SetHeader(header)
table.SetAlignment(tablewriter.ALIGN_LEFT)
// table.SetColumnAlignment([]int{
// tablewriter.ALIGN_LEFT,
// tablewriter.ALIGN_LEFT,
// tablewriter.ALIGN_LEFT,
// tablewriter.ALIGN_LEFT,
// tablewriter.ALIGN_CENTER,
// tablewriter.ALIGN_RIGHT,
// tablewriter.ALIGN_LEFT,
// })
// table.SetCaption(true, title)
// Markdown format.
// table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
// table.SetCenterSeparator("|")
results = results[1:len(results)]
for i := range results {
table.Append(results[i])
}
table.Render()
}