-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
82 lines (68 loc) · 1.84 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
75
76
77
78
79
80
81
82
package main
import (
"bytes"
_ "embed"
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/mymmrac/chipper/core"
"github.com/mymmrac/chipper/tests"
)
//go:embed config.yaml
var configData []byte
var rootCmd = &cobra.Command{
Use: "chipper",
Short: "Chipper is small tool for testing CPUs",
Args: cobra.NoArgs,
Version: "v0.2.0",
Run: run,
}
func main() {
viper.SetConfigType("yaml")
if err := viper.ReadConfig(bytes.NewBuffer(configData)); err != nil {
fmt.Printf("Failed to read config: %v\n", err)
os.Exit(1)
}
rootCmd.Flags().BoolP("simple-mode", "s", false, "Enable simple mode")
if err := viper.BindPFlag("simple-mode", rootCmd.Flags().Lookup("simple-mode")); err != nil {
fmt.Printf("Failed to bind flag: %v\n", err)
os.Exit(1)
}
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func run(_ *cobra.Command, _ []string) {
var tcs tests.TestCases
if err := viper.UnmarshalKey("test-case-list", &tcs); err != nil {
fmt.Printf("Failed to get test cases: %v\n", err)
os.Exit(1)
}
testList, err := tests.ParseTestCases(tcs)
if err != nil {
fmt.Printf("Failed to parce test cases: %v\n", err)
os.Exit(1)
}
if len(testList) == 0 {
fmt.Println("No test cases found")
os.Exit(1)
}
progressReadInterval := viper.GetDuration("progress-read-interval")
if progressReadInterval == 0 {
fmt.Println("Progress read interval can't be 0")
os.Exit(1)
}
if viper.GetBool("simple-mode") {
core.ExecuteTests(testList, progressReadInterval, &simpleTerminalExecutor{})
} else {
bubbleExecutor := newBubbleTeaExecutor(testList, progressReadInterval)
program := tea.NewProgram(bubbleExecutor)
bubbleExecutor.setProgram(program)
if err = program.Start(); err != nil {
fmt.Printf("Failed to start bubble tea: %v", err)
os.Exit(1)
}
}
}