github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/puppeth/puppeth.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:33</date> 10 //</624450069638156288> 11 12 13 //Puppeth是一个集合和维护私有网络的命令。 14 package main 15 16 import ( 17 "math/rand" 18 "os" 19 "strings" 20 "time" 21 22 "github.com/ethereum/go-ethereum/log" 23 "gopkg.in/urfave/cli.v1" 24 ) 25 26 // 27 func main() { 28 app := cli.NewApp() 29 app.Name = "puppeth" 30 app.Usage = "assemble and maintain private Ethereum networks" 31 app.Flags = []cli.Flag{ 32 cli.StringFlag{ 33 Name: "network", 34 Usage: "name of the network to administer (no spaces or hyphens, please)", 35 }, 36 cli.IntFlag{ 37 Name: "loglevel", 38 Value: 3, 39 Usage: "log level to emit to the screen", 40 }, 41 } 42 app.Before = func(c *cli.Context) error { 43 //设置记录器以打印所有内容和随机生成器 44 log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int("loglevel")), log.StreamHandler(os.Stdout, log.TerminalFormat(true)))) 45 rand.Seed(time.Now().UnixNano()) 46 47 return nil 48 } 49 app.Action = runWizard 50 app.Run(os.Args) 51 } 52 53 // 54 func runWizard(c *cli.Context) error { 55 network := c.String("network") 56 if strings.Contains(network, " ") || strings.Contains(network, "-") || strings.ToLower(network) != network { 57 log.Crit("No spaces, hyphens or capital letters allowed in network name") 58 } 59 makeWizard(c.String("network")).run() 60 return nil 61 } 62