forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
54 lines (44 loc) · 1.23 KB
/
root.go
File metadata and controls
54 lines (44 loc) · 1.23 KB
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
package cmd
import (
"fmt"
"os"
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
client "github.com/textileio/powergate/api/client"
"github.com/textileio/powergate/buildinfo"
)
var (
fcClient *client.Client
cmdTimeout = time.Second * 10
rootCmd = &cobra.Command{
Use: "pow",
Short: "A client for storage and retreival of powergate data",
Long: `A client for storage and retreival of powergate data`,
Version: buildinfo.Summary(),
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
err := viper.BindPFlag("serverAddress", cmd.Root().PersistentFlags().Lookup("serverAddress"))
checkErr(err)
target := viper.GetString("serverAddress")
fcClient, err = client.NewClient(target)
checkErr(err)
},
}
)
// Execute runs the root command.
func Execute() {
rootCmd.SetVersionTemplate("pow build info:\n{{.Version}}\n")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().String("serverAddress", "127.0.0.1:5002", "address of the powergate service api")
}
func initConfig() {
viper.SetEnvPrefix("POW")
viper.AutomaticEnv()
}