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