github.com/codingfuture/orig-energi3@v0.8.4/cmd/puppeth/puppeth.go (about) 1 // Copyright 2018 The Energi Core Authors 2 // Copyright 2017 The go-ethereum Authors 3 // This file is part of Energi Core. 4 // 5 // Energi Core is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Energi Core is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Energi Core. If not, see <http://www.gnu.org/licenses/>. 17 18 // puppeth is a command to assemble and maintain private networks. 19 package main 20 21 import ( 22 "math/rand" 23 "os" 24 "strings" 25 "time" 26 27 "github.com/ethereum/go-ethereum/log" 28 "gopkg.in/urfave/cli.v1" 29 ) 30 31 // main is just a boring entry point to set up the CLI app. 32 func main() { 33 app := cli.NewApp() 34 app.Name = "puppeth" 35 app.Usage = "assemble and maintain private Energi networks" 36 app.Flags = []cli.Flag{ 37 cli.StringFlag{ 38 Name: "network", 39 Usage: "name of the network to administer (no spaces or hyphens, please)", 40 }, 41 cli.IntFlag{ 42 Name: "loglevel", 43 Value: 3, 44 Usage: "log level to emit to the screen", 45 }, 46 } 47 app.Before = func(c *cli.Context) error { 48 // Set up the logger to print everything and the random generator 49 log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int("loglevel")), log.StreamHandler(os.Stdout, log.TerminalFormat(true)))) 50 rand.Seed(time.Now().UnixNano()) 51 52 return nil 53 } 54 app.Action = runWizard 55 app.Run(os.Args) 56 } 57 58 // runWizard start the wizard and relinquish control to it. 59 func runWizard(c *cli.Context) error { 60 network := c.String("network") 61 if strings.Contains(network, " ") || strings.Contains(network, "-") || strings.ToLower(network) != network { 62 log.Crit("No spaces, hyphens or capital letters allowed in network name") 63 } 64 makeWizard(c.String("network")).run() 65 return nil 66 }