-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
69 lines (57 loc) · 1.3 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
package cmd
import (
"fmt"
"os"
"github.com/gomicro/align/client"
configcmd "github.com/gomicro/align/cmd/config"
"github.com/gomicro/align/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
clt *client.Client
)
func init() {
cobra.OnInitialize(initEnvs)
rootCmd.AddCommand(
authCmd,
completionCmd,
cloneCmd,
checkoutCmd,
pullCmd,
versionCmd,
configcmd.ConfigCmd,
)
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show more verbose output")
err := viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
if err != nil {
fmt.Printf("Error setting up: %v\n", err.Error())
os.Exit(1)
}
}
func initEnvs() {
}
var rootCmd = &cobra.Command{
Use: "align [flags]",
Short: "Tool for managing repos",
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute: %v\n", err.Error())
os.Exit(1)
}
}
func setupClient(cmd *cobra.Command, args []string) {
c, err := config.ParseFromFile()
if err != nil {
fmt.Printf("Error: %v", err.Error())
os.Exit(1)
}
clt, err = client.New(c)
if err != nil {
fmt.Printf("Error: %v", err.Error())
os.Exit(1)
}
}