OSDN Git Service

Hulk did something
[bytom/vapor.git] / cmd / bytomd / commands / init.go
1 package commands
2
3 import (
4         "os"
5         "path"
6
7         log "github.com/sirupsen/logrus"
8         "github.com/spf13/cobra"
9
10         cfg "github.com/vapor/config"
11 )
12
13 var initFilesCmd = &cobra.Command{
14         Use:   "init",
15         Short: "Initialize blockchain",
16         Run:   initFiles,
17 }
18
19 func init() {
20         initFilesCmd.Flags().String("chain_id", config.ChainID, "Select [mainnet] or [testnet] or [solonet]")
21
22         RootCmd.AddCommand(initFilesCmd)
23 }
24
25 func initFiles(cmd *cobra.Command, args []string) {
26         configFilePath := path.Join(config.RootDir, "config.toml")
27         if _, err := os.Stat(configFilePath); !os.IsNotExist(err) {
28                 log.WithFields(log.Fields{"module": logModule, "config": configFilePath}).Info("Already exists config file.")
29                 return
30         }
31
32         switch config.ChainID {
33         case "mainnet", "testnet":
34                 cfg.EnsureRoot(config.RootDir, config.ChainID)
35         default:
36                 cfg.EnsureRoot(config.RootDir, "solonet")
37         }
38
39         log.WithFields(log.Fields{"module": logModule, "config": configFilePath}).Info("Initialized bytom")
40 }