/
init.go
65 lines (56 loc) · 1.91 KB
/
init.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
package utilscmd
import (
"github.com/lasthyphen/ecctools/pkg/configs"
"github.com/lasthyphen/ecctools/pkg/utils"
"github.com/spf13/cobra"
)
func newInitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "init [avago-version] [subnet-evm-version]",
Short: "Create default files in the current dir",
Long: `Create default config files in the current dir, and
also attempt to download avalanchego and subnet-evm binaries from
GitHub.
Example: ggt init v1.9.7 v0.4.8
`,
Run: func(cmd *cobra.Command, args []string) {
files := make(map[string]string)
files["README.md"] = configs.Readme
files["subnetevm-genesis.json"] = configs.SubnetEVMGenesis
files["subnetevm-config.json"] = configs.SubnetEVMConfig
files[configs.AccountsFilename] = configs.Accounts
files[configs.CChainConfigFilename] = configs.CChainConfig
files[configs.ContractsFilename] = configs.Contracts
files[configs.NodeConfigFilename] = configs.NodeConfig
files[configs.XChainConfigFilename] = configs.XChainConfig
files[configs.AvaGenesisFilename] = configs.AvaGenesis
for fn, content := range files {
if utils.FileExists(fn) {
app.Log.Infof("File exists, skipping %s", fn)
} else {
app.Log.Infof("Creating %s", fn)
_ = utils.WriteFileBytes(fn, []byte(content))
}
}
if len(args) > 0 && args[0] != "" {
app.Log.Infof("Downloading avalanchego...")
url, destFile, err := utils.DownloadAvalanchego(".", args[0])
if err != nil {
app.Log.Warnf("Error downloading %s: %s", url, err)
} else {
app.Log.Infof("Downloaded %s to %s", url, destFile)
}
}
if len(args) > 1 && args[1] != "" {
app.Log.Infof("Downloading subnetevm...")
url, destFile, err := utils.DownloadSubnetevm(".", args[1])
if err != nil {
app.Log.Warnf("Error downloading %s: %s", url, err)
} else {
app.Log.Infof("Downloaded %s to %s", url, destFile)
}
}
},
}
return cmd
}