-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (65 loc) · 1.48 KB
/
main.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
71
72
73
74
package main
import (
"os"
"strings"
"github.com/merschformann/gobenchtransform/benchconvert"
"github.com/spf13/cobra"
_ "embed"
)
//go:embed VERSION
var Version string
func main() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.Flags().StringP("input", "i", "", "input file (default is stdin)")
rootCmd.Flags().StringP("output", "o", "", "output file (default is stdout)")
rootCmd.Flags().BoolP("quiet", "q", false, "suppress repeating output to stdout")
}
var rootCmd = &cobra.Command{
Use: "gobenchtransform",
Version: strings.Trim(Version, "\n"),
Short: "Transform Go benchmark results into a format that can be used by other tools.",
Run: func(cmd *cobra.Command, _ []string) {
// Get the input and output files.
inputFile, err := cmd.Flags().GetString("input")
if err != nil {
panic(err)
}
outputFile, err := cmd.Flags().GetString("output")
if err != nil {
panic(err)
}
quiet, err := cmd.Flags().GetBool("quiet")
if err != nil {
panic(err)
}
// Get input and output streams.
var input *os.File
if inputFile == "" {
input = os.Stdin
} else {
input, err = os.Open(inputFile)
if err != nil {
panic(err)
}
}
var output *os.File
if outputFile == "" {
output = os.Stdout
} else {
output, err = os.Create(outputFile)
if err != nil {
panic(err)
}
}
// Convert the input to CSV.
err = benchconvert.ConvertToCSV(input, output, quiet)
if err != nil {
panic(err)
}
},
}