github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/cmd/burrow/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 8 "github.com/hyperledger/burrow/cmd/burrow/commands" 9 "github.com/hyperledger/burrow/project" 10 cli "github.com/jawher/mow.cli" 11 ) 12 13 func main() { 14 output := defaultOutput() 15 err := burrow(output).Run(os.Args) 16 if err != nil { 17 output.Fatalf("%v", err) 18 } 19 } 20 21 func burrow(output commands.Output) *cli.Cli { 22 app := cli.App("burrow", "The EVM smart contract machine with Tendermint consensus") 23 // We'll handle any errors 24 app.ErrorHandling = flag.ContinueOnError 25 26 versionOpt := app.BoolOpt("v version", false, "Print the Burrow version") 27 chDirOpt := app.StringOpt("C directory", "", "Change directory before running") 28 app.Spec = "[--version] [--directory=<working directory>]" 29 30 app.Before = func() { 31 if *chDirOpt != "" { 32 err := os.Chdir(*chDirOpt) 33 if err != nil { 34 output.Fatalf("Could not change working directory to %s: %v", *chDirOpt, err) 35 } 36 } 37 } 38 39 app.Action = func() { 40 if *versionOpt { 41 fmt.Println(project.FullVersion()) 42 } else { 43 app.PrintHelp() 44 } 45 } 46 47 app.Command("start", "Start a Burrow node", 48 commands.Start(output)) 49 50 app.Command("spec", "Build a GenesisSpec that acts as a template for a GenesisDoc and the configure command", 51 commands.Spec(output)) 52 53 app.Command("configure", 54 "Create Burrow configuration by consuming a GenesisDoc or GenesisSpec, creating keys, and emitting the config", 55 commands.Configure(output)) 56 57 app.Command("keys", "A tool for doing a bunch of cool stuff with keys", 58 commands.Keys(output)) 59 60 app.Command("explore", "Dump objects from an offline Burrow .burrow directory", 61 commands.Explore(output)) 62 63 app.Command("deploy", "Deploy and test contracts", 64 commands.Deploy(output)) 65 66 app.Command("natives", "Dump Solidity interface contracts for Burrow native contracts", 67 commands.Natives(output)) 68 69 app.Command("vent", "Start the Vent EVM event and blocks consumer service to populated databases from smart contracts", 70 commands.Vent(output)) 71 72 app.Command("dump", "Dump chain state to backup", 73 commands.Dump(output)) 74 75 app.Command("tx", "Submit a transaction to a burrow node", 76 commands.Tx(output)) 77 78 app.Command("restore", "Restore new chain from backup", 79 commands.Restore(output)) 80 81 app.Command("accounts", "List accounts and metadata", 82 commands.Accounts(output)) 83 84 app.Command("abi", "List, decode and encode using ABI", 85 commands.Abi(output)) 86 87 app.Command("compile", "Compile solidity files embedding the compilation results as a fixture in a Go file", 88 commands.Compile(output)) 89 90 app.Command("errors", "Print error codes", 91 commands.Errors(output)) 92 return app 93 } 94 95 func defaultOutput() *output { 96 return &output{ 97 PrintfFunc: func(format string, args ...interface{}) { 98 fmt.Fprintf(os.Stdout, format+"\n", args...) 99 }, 100 LogfFunc: func(format string, args ...interface{}) { 101 fmt.Fprintf(os.Stderr, format+"\n", args...) 102 }, 103 FatalfFunc: func(format string, args ...interface{}) { 104 fmt.Fprintf(os.Stderr, format+"\n", args...) 105 os.Exit(1) 106 }, 107 } 108 } 109 110 type output struct { 111 PrintfFunc func(format string, args ...interface{}) 112 LogfFunc func(format string, args ...interface{}) 113 FatalfFunc func(format string, args ...interface{}) 114 } 115 116 func (out *output) Printf(format string, args ...interface{}) { 117 out.PrintfFunc(format, args...) 118 } 119 120 func (out *output) Logf(format string, args ...interface{}) { 121 out.LogfFunc(format, args...) 122 } 123 124 func (out *output) Fatalf(format string, args ...interface{}) { 125 out.FatalfFunc(format, args...) 126 }