-
Notifications
You must be signed in to change notification settings - Fork 2
/
root.go
58 lines (51 loc) · 933 Bytes
/
root.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
package cmd
import (
"os"
curver "github.com/harakeishi/curver"
trv "github.com/harakeishi/trv/trv"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "trv",
Short: "`trv` is a remote viewer for tbls",
Long: "`trv` is a remote viewer for tbls",
RunE: func(cmd *cobra.Command, args []string) error {
version, err := cmd.Flags().GetBool("version")
if err != nil {
return err
}
if version {
curver.EchoVersion()
return nil
}
var trv trv.Trv
exists, err := trv.Config.Exists()
if err != nil {
return err
}
if exists {
err = trv.Init()
if err != nil {
return err
}
trv.Draw()
} else {
trv.CreateConfig()
err = trv.Init()
if err != nil {
return err
}
trv.Draw()
}
return nil
},
}
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.Flags().BoolP("version", "V", false, "echo version")
}