github.com/pfcoder/quorum@v2.0.3-0.20180501191142-d4a1b0958135+incompatible/cmd/geth/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 geth command usage template and generator. 18 19 package main 20 21 import ( 22 "io" 23 "sort" 24 25 "github.com/ethereum/go-ethereum/cmd/utils" 26 "github.com/ethereum/go-ethereum/internal/debug" 27 "gopkg.in/urfave/cli.v1" 28 ) 29 30 // AppHelpTemplate is the test template for the default, global app help topic. 31 var AppHelpTemplate = `NAME: 32 {{.App.Name}} - {{.App.Usage}} 33 34 Copyright 2013-2017 The go-ethereum Authors 35 36 USAGE: 37 {{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}} 38 {{if .App.Version}} 39 VERSION: 40 {{.App.Version}} 41 {{end}}{{if len .App.Authors}} 42 AUTHOR(S): 43 {{range .App.Authors}}{{ . }}{{end}} 44 {{end}}{{if .App.Commands}} 45 COMMANDS: 46 {{range .App.Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} 47 {{end}}{{end}}{{if .FlagGroups}} 48 {{range .FlagGroups}}{{.Name}} OPTIONS: 49 {{range .Flags}}{{.}} 50 {{end}} 51 {{end}}{{end}}{{if .App.Copyright }} 52 COPYRIGHT: 53 {{.App.Copyright}} 54 {{end}} 55 ` 56 57 // flagGroup is a collection of flags belonging to a single topic. 58 type flagGroup struct { 59 Name string 60 Flags []cli.Flag 61 } 62 63 // AppHelpFlagGroups is the application flags, grouped by functionality. 64 var AppHelpFlagGroups = []flagGroup{ 65 { 66 Name: "ETHEREUM", 67 Flags: []cli.Flag{ 68 configFileFlag, 69 utils.DataDirFlag, 70 utils.KeyStoreDirFlag, 71 utils.NoUSBFlag, 72 utils.NetworkIdFlag, 73 utils.TestnetFlag, 74 utils.RinkebyFlag, 75 utils.OttomanFlag, 76 utils.DevModeFlag, 77 utils.SyncModeFlag, 78 utils.EthStatsURLFlag, 79 utils.IdentityFlag, 80 utils.LightServFlag, 81 utils.LightPeersFlag, 82 utils.LightKDFFlag, 83 }, 84 }, 85 { 86 Name: "ETHASH", 87 Flags: []cli.Flag{ 88 utils.EthashCacheDirFlag, 89 utils.EthashCachesInMemoryFlag, 90 utils.EthashCachesOnDiskFlag, 91 utils.EthashDatasetDirFlag, 92 utils.EthashDatasetsInMemoryFlag, 93 utils.EthashDatasetsOnDiskFlag, 94 }, 95 }, 96 { 97 Name: "TRANSACTION POOL", 98 Flags: []cli.Flag{ 99 utils.TxPoolNoLocalsFlag, 100 utils.TxPoolJournalFlag, 101 utils.TxPoolRejournalFlag, 102 utils.TxPoolPriceLimitFlag, 103 utils.TxPoolPriceBumpFlag, 104 utils.TxPoolAccountSlotsFlag, 105 utils.TxPoolGlobalSlotsFlag, 106 utils.TxPoolAccountQueueFlag, 107 utils.TxPoolGlobalQueueFlag, 108 utils.TxPoolLifetimeFlag, 109 }, 110 }, 111 { 112 Name: "PERFORMANCE TUNING", 113 Flags: []cli.Flag{ 114 utils.CacheFlag, 115 utils.TrieCacheGenFlag, 116 }, 117 }, 118 { 119 Name: "QUORUM", 120 Flags: []cli.Flag{ 121 utils.EnableNodePermissionFlag, 122 }, 123 }, 124 { 125 Name: "RAFT", 126 Flags: []cli.Flag{ 127 utils.RaftModeFlag, 128 utils.RaftBlockTimeFlag, 129 utils.RaftJoinExistingFlag, 130 utils.RaftPortFlag, 131 }, 132 }, 133 { 134 Name: "ACCOUNT", 135 Flags: []cli.Flag{ 136 utils.UnlockedAccountFlag, 137 utils.PasswordFileFlag, 138 }, 139 }, 140 { 141 Name: "API AND CONSOLE", 142 Flags: []cli.Flag{ 143 utils.RPCEnabledFlag, 144 utils.RPCListenAddrFlag, 145 utils.RPCPortFlag, 146 utils.RPCApiFlag, 147 utils.WSEnabledFlag, 148 utils.WSListenAddrFlag, 149 utils.WSPortFlag, 150 utils.WSApiFlag, 151 utils.WSAllowedOriginsFlag, 152 utils.IPCDisabledFlag, 153 utils.IPCPathFlag, 154 utils.RPCCORSDomainFlag, 155 utils.JSpathFlag, 156 utils.ExecFlag, 157 utils.PreloadJSFlag, 158 }, 159 }, 160 { 161 Name: "NETWORKING", 162 Flags: []cli.Flag{ 163 utils.BootnodesFlag, 164 utils.BootnodesV4Flag, 165 utils.BootnodesV5Flag, 166 utils.ListenPortFlag, 167 utils.MaxPeersFlag, 168 utils.MaxPendingPeersFlag, 169 utils.NATFlag, 170 utils.NoDiscoverFlag, 171 utils.DiscoveryV5Flag, 172 utils.NetrestrictFlag, 173 utils.NodeKeyFileFlag, 174 utils.NodeKeyHexFlag, 175 }, 176 }, 177 { 178 Name: "MINER", 179 Flags: []cli.Flag{ 180 utils.MiningEnabledFlag, 181 utils.MinerThreadsFlag, 182 utils.EtherbaseFlag, 183 utils.TargetGasLimitFlag, 184 utils.GasPriceFlag, 185 utils.ExtraDataFlag, 186 }, 187 }, 188 { 189 Name: "GAS PRICE ORACLE", 190 Flags: []cli.Flag{ 191 utils.GpoBlocksFlag, 192 utils.GpoPercentileFlag, 193 }, 194 }, 195 { 196 Name: "VIRTUAL MACHINE", 197 Flags: []cli.Flag{ 198 utils.VMEnableDebugFlag, 199 }, 200 }, 201 { 202 Name: "LOGGING AND DEBUGGING", 203 Flags: append([]cli.Flag{ 204 utils.MetricsEnabledFlag, 205 utils.FakePoWFlag, 206 utils.NoCompactionFlag, 207 }, debug.Flags...), 208 }, 209 { 210 Name: "WHISPER (EXPERIMENTAL)", 211 Flags: whisperFlags, 212 }, 213 { 214 Name: "DEPRECATED", 215 Flags: []cli.Flag{ 216 utils.FastSyncFlag, 217 utils.LightModeFlag, 218 }, 219 }, 220 { 221 Name: "MISC", 222 }, 223 { 224 Name: "ISTANBUL", 225 Flags: []cli.Flag{ 226 utils.IstanbulRequestTimeoutFlag, 227 utils.IstanbulBlockPeriodFlag, 228 }, 229 }, 230 } 231 232 // byCategory sorts an array of flagGroup by Name in the order 233 // defined in AppHelpFlagGroups. 234 type byCategory []flagGroup 235 236 func (a byCategory) Len() int { return len(a) } 237 func (a byCategory) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 238 func (a byCategory) Less(i, j int) bool { 239 iCat, jCat := a[i].Name, a[j].Name 240 iIdx, jIdx := len(AppHelpFlagGroups), len(AppHelpFlagGroups) // ensure non categorized flags come last 241 242 for i, group := range AppHelpFlagGroups { 243 if iCat == group.Name { 244 iIdx = i 245 } 246 if jCat == group.Name { 247 jIdx = i 248 } 249 } 250 251 return iIdx < jIdx 252 } 253 254 func flagCategory(flag cli.Flag) string { 255 for _, category := range AppHelpFlagGroups { 256 for _, flg := range category.Flags { 257 if flg.GetName() == flag.GetName() { 258 return category.Name 259 } 260 } 261 } 262 return "MISC" 263 } 264 265 func init() { 266 // Override the default app help template 267 cli.AppHelpTemplate = AppHelpTemplate 268 269 // Define a one shot struct to pass to the usage template 270 type helpData struct { 271 App interface{} 272 FlagGroups []flagGroup 273 } 274 275 // Override the default app help printer, but only for the global app help 276 originalHelpPrinter := cli.HelpPrinter 277 cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) { 278 if tmpl == AppHelpTemplate { 279 // Iterate over all the flags and add any uncategorized ones 280 categorized := make(map[string]struct{}) 281 for _, group := range AppHelpFlagGroups { 282 for _, flag := range group.Flags { 283 categorized[flag.String()] = struct{}{} 284 } 285 } 286 uncategorized := []cli.Flag{} 287 for _, flag := range data.(*cli.App).Flags { 288 if _, ok := categorized[flag.String()]; !ok { 289 uncategorized = append(uncategorized, flag) 290 } 291 } 292 if len(uncategorized) > 0 { 293 // Append all ungategorized options to the misc group 294 miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags) 295 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...) 296 297 // Make sure they are removed afterwards 298 defer func() { 299 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs] 300 }() 301 } 302 // Render out custom usage screen 303 originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups}) 304 } else if tmpl == utils.CommandHelpTemplate { 305 // Iterate over all command specific flags and categorize them 306 categorized := make(map[string][]cli.Flag) 307 for _, flag := range data.(cli.Command).Flags { 308 if _, ok := categorized[flag.String()]; !ok { 309 categorized[flagCategory(flag)] = append(categorized[flagCategory(flag)], flag) 310 } 311 } 312 313 // sort to get a stable ordering 314 sorted := make([]flagGroup, 0, len(categorized)) 315 for cat, flgs := range categorized { 316 sorted = append(sorted, flagGroup{cat, flgs}) 317 } 318 sort.Sort(byCategory(sorted)) 319 320 // add sorted array to data and render with default printer 321 originalHelpPrinter(w, tmpl, map[string]interface{}{ 322 "cmd": data, 323 "categorizedFlags": sorted, 324 }) 325 } else { 326 originalHelpPrinter(w, tmpl, data) 327 } 328 } 329 }