github.com/digdeepmining/go-atheios@v1.5.13-0.20180902133602-d5687a2e6f43/cmd/gath/usage.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 // Contains the gath command usage template and generator. 18 19 package main 20 21 import ( 22 "io" 23 24 "github.com/atheioschain/go-atheios/cmd/utils" 25 "github.com/atheioschain/go-atheios/internal/debug" 26 "gopkg.in/urfave/cli.v1" 27 ) 28 29 // AppHelpTemplate is the test template for the default, global app help topic. 30 var AppHelpTemplate = `NAME: 31 {{.App.Name}} - {{.App.Usage}} 32 33 Copyright 2013-2016 The go-atheios Authors 34 35 USAGE: 36 {{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}} 37 {{if .App.Version}} 38 VERSION: 39 {{.App.Version}} 40 {{end}}{{if len .App.Authors}} 41 AUTHOR(S): 42 {{range .App.Authors}}{{ . }}{{end}} 43 {{end}}{{if .App.Commands}} 44 COMMANDS: 45 {{range .App.Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} 46 {{end}}{{end}}{{if .FlagGroups}} 47 {{range .FlagGroups}}{{.Name}} OPTIONS: 48 {{range .Flags}}{{.}} 49 {{end}} 50 {{end}}{{end}}{{if .App.Copyright }} 51 COPYRIGHT: 52 {{.App.Copyright}} 53 {{end}} 54 ` 55 56 // flagGroup is a collection of flags belonging to a single topic. 57 type flagGroup struct { 58 Name string 59 Flags []cli.Flag 60 } 61 62 // AppHelpFlagGroups is the application flags, grouped by functionality. 63 var AppHelpFlagGroups = []flagGroup{ 64 { 65 Name: "ETHEREUM", 66 Flags: []cli.Flag{ 67 utils.DataDirFlag, 68 utils.KeyStoreDirFlag, 69 utils.NetworkIdFlag, 70 utils.TestNetFlag, 71 utils.DevModeFlag, 72 utils.IdentityFlag, 73 utils.FastSyncFlag, 74 utils.LightModeFlag, 75 utils.LightServFlag, 76 utils.LightPeersFlag, 77 utils.LightKDFFlag, 78 }, 79 }, 80 { 81 Name: "PERFORMANCE TUNING", 82 Flags: []cli.Flag{ 83 utils.CacheFlag, 84 utils.TrieCacheGenFlag, 85 }, 86 }, 87 { 88 Name: "ACCOUNT", 89 Flags: []cli.Flag{ 90 utils.UnlockedAccountFlag, 91 utils.PasswordFileFlag, 92 }, 93 }, 94 { 95 Name: "API AND CONSOLE", 96 Flags: []cli.Flag{ 97 utils.RPCEnabledFlag, 98 utils.RPCListenAddrFlag, 99 utils.RPCPortFlag, 100 utils.RPCApiFlag, 101 utils.WSEnabledFlag, 102 utils.WSListenAddrFlag, 103 utils.WSPortFlag, 104 utils.WSApiFlag, 105 utils.WSAllowedOriginsFlag, 106 utils.IPCDisabledFlag, 107 utils.IPCApiFlag, 108 utils.IPCPathFlag, 109 utils.RPCCORSDomainFlag, 110 utils.JSpathFlag, 111 utils.ExecFlag, 112 utils.PreloadJSFlag, 113 }, 114 }, 115 { 116 Name: "NETWORKING", 117 Flags: []cli.Flag{ 118 utils.BootnodesFlag, 119 utils.ListenPortFlag, 120 utils.MaxPeersFlag, 121 utils.MaxPendingPeersFlag, 122 utils.NATFlag, 123 utils.NoDiscoverFlag, 124 utils.DiscoveryV5Flag, 125 utils.NodeKeyFileFlag, 126 utils.NodeKeyHexFlag, 127 }, 128 }, 129 { 130 Name: "MINER", 131 Flags: []cli.Flag{ 132 utils.MiningEnabledFlag, 133 utils.MinerThreadsFlag, 134 utils.AutoDAGFlag, 135 utils.EtherbaseFlag, 136 utils.TargetGasLimitFlag, 137 utils.GasPriceFlag, 138 utils.ExtraDataFlag, 139 }, 140 }, 141 { 142 Name: "GAS PRICE ORACLE", 143 Flags: []cli.Flag{ 144 utils.GpoMinGasPriceFlag, 145 utils.GpoMaxGasPriceFlag, 146 utils.GpoFullBlockRatioFlag, 147 utils.GpobaseStepDownFlag, 148 utils.GpobaseStepUpFlag, 149 utils.GpobaseCorrectionFactorFlag, 150 }, 151 }, 152 { 153 Name: "VIRTUAL MACHINE", 154 Flags: []cli.Flag{ 155 utils.VMEnableJitFlag, 156 utils.VMForceJitFlag, 157 utils.VMJitCacheFlag, 158 utils.VMEnableDebugFlag, 159 }, 160 }, 161 { 162 Name: "LOGGING AND DEBUGGING", 163 Flags: append([]cli.Flag{ 164 utils.EthStatsURLFlag, 165 utils.MetricsEnabledFlag, 166 utils.FakePoWFlag, 167 }, debug.Flags...), 168 }, 169 { 170 Name: "EXPERIMENTAL", 171 Flags: []cli.Flag{ 172 utils.WhisperEnabledFlag, 173 }, 174 }, 175 { 176 Name: "MISCELLANEOUS", 177 Flags: []cli.Flag{ 178 utils.SolcPathFlag, 179 }, 180 }, 181 } 182 183 func init() { 184 // Override the default app help template 185 cli.AppHelpTemplate = AppHelpTemplate 186 187 // Define a one shot struct to pass to the usage template 188 type helpData struct { 189 App interface{} 190 FlagGroups []flagGroup 191 } 192 // Override the default app help printer, but only for the global app help 193 originalHelpPrinter := cli.HelpPrinter 194 cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) { 195 if tmpl == AppHelpTemplate { 196 // Iterate over all the flags and add any uncategorized ones 197 categorized := make(map[string]struct{}) 198 for _, group := range AppHelpFlagGroups { 199 for _, flag := range group.Flags { 200 categorized[flag.String()] = struct{}{} 201 } 202 } 203 uncategorized := []cli.Flag{} 204 for _, flag := range data.(*cli.App).Flags { 205 if _, ok := categorized[flag.String()]; !ok { 206 uncategorized = append(uncategorized, flag) 207 } 208 } 209 if len(uncategorized) > 0 { 210 // Append all ungategorized options to the misc group 211 miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags) 212 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...) 213 214 // Make sure they are removed afterwards 215 defer func() { 216 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs] 217 }() 218 } 219 // Render out custom usage screen 220 originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups}) 221 } else { 222 originalHelpPrinter(w, tmpl, data) 223 } 224 } 225 }