OSDN Git Service

Mov (#518)
[bytom/vapor.git] / cmd / vapord / commands / root.go
1 package commands
2
3 import (
4         "os/user"
5         "strings"
6
7         "github.com/spf13/cobra"
8         "github.com/spf13/viper"
9         cmn "github.com/tendermint/tmlibs/common"
10
11         cfg "github.com/bytom/vapor/config"
12 )
13
14 var (
15         config = cfg.DefaultConfig()
16 )
17
18 // RootCmd is the command for run node
19 var RootCmd = &cobra.Command{
20         Use:   "vapord",
21         Short: "Multiple asset management.",
22         PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
23                 err := viper.Unmarshal(config)
24                 if err != nil {
25                         return err
26                 }
27                 pathParts := strings.SplitN(config.RootDir, "/", 2)
28                 if len(pathParts) == 2 && (pathParts[0] == "~" || pathParts[0] == "$HOME") {
29                         usr, err := user.Current()
30                         if err != nil {
31                                 cmn.Exit("Error: " + err.Error())
32                         }
33                         pathParts[0] = usr.HomeDir
34                         config.RootDir = strings.Join(pathParts, "/")
35                 }
36                 config.SetRoot(config.RootDir)
37                 return nil
38         },
39 }