github.com/MaynardMiner/ethereumprogpow@v1.8.23/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/ethereumprogpow/ethereumprogpow/cmd/utils" 28 "github.com/ethereumprogpow/ethereumprogpow/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.GangnamFlag, 78 utils.SyncModeFlag, 79 utils.GCModeFlag, 80 utils.EthStatsURLFlag, 81 utils.IdentityFlag, 82 utils.LightServFlag, 83 utils.LightPeersFlag, 84 utils.LightKDFFlag, 85 utils.WhitelistFlag, 86 }, 87 }, 88 { 89 Name: "DEVELOPER CHAIN", 90 Flags: []cli.Flag{ 91 utils.DeveloperFlag, 92 utils.DeveloperPeriodFlag, 93 }, 94 }, 95 { 96 Name: "ETHASH", 97 Flags: []cli.Flag{ 98 utils.EthashCacheDirFlag, 99 utils.EthashCachesInMemoryFlag, 100 utils.EthashCachesOnDiskFlag, 101 utils.EthashDatasetDirFlag, 102 utils.EthashDatasetsInMemoryFlag, 103 utils.EthashDatasetsOnDiskFlag, 104 }, 105 }, 106 //{ 107 // Name: "DASHBOARD", 108 // Flags: []cli.Flag{ 109 // utils.DashboardEnabledFlag, 110 // utils.DashboardAddrFlag, 111 // utils.DashboardPortFlag, 112 // utils.DashboardRefreshFlag, 113 // utils.DashboardAssetsFlag, 114 // }, 115 //}, 116 { 117 Name: "TRANSACTION POOL", 118 Flags: []cli.Flag{ 119 utils.TxPoolLocalsFlag, 120 utils.TxPoolNoLocalsFlag, 121 utils.TxPoolJournalFlag, 122 utils.TxPoolRejournalFlag, 123 utils.TxPoolPriceLimitFlag, 124 utils.TxPoolPriceBumpFlag, 125 utils.TxPoolAccountSlotsFlag, 126 utils.TxPoolGlobalSlotsFlag, 127 utils.TxPoolAccountQueueFlag, 128 utils.TxPoolGlobalQueueFlag, 129 utils.TxPoolLifetimeFlag, 130 }, 131 }, 132 { 133 Name: "PERFORMANCE TUNING", 134 Flags: []cli.Flag{ 135 utils.CacheFlag, 136 utils.CacheDatabaseFlag, 137 utils.CacheTrieFlag, 138 utils.CacheGCFlag, 139 utils.TrieCacheGenFlag, 140 }, 141 }, 142 { 143 Name: "ACCOUNT", 144 Flags: []cli.Flag{ 145 utils.UnlockedAccountFlag, 146 utils.PasswordFileFlag, 147 }, 148 }, 149 { 150 Name: "API AND CONSOLE", 151 Flags: []cli.Flag{ 152 utils.RPCEnabledFlag, 153 utils.RPCListenAddrFlag, 154 utils.RPCPortFlag, 155 utils.RPCApiFlag, 156 utils.WSEnabledFlag, 157 utils.WSListenAddrFlag, 158 utils.WSPortFlag, 159 utils.WSApiFlag, 160 utils.WSAllowedOriginsFlag, 161 utils.IPCDisabledFlag, 162 utils.IPCPathFlag, 163 utils.RPCCORSDomainFlag, 164 utils.RPCVirtualHostsFlag, 165 utils.JSpathFlag, 166 utils.ExecFlag, 167 utils.PreloadJSFlag, 168 }, 169 }, 170 { 171 Name: "NETWORKING", 172 Flags: []cli.Flag{ 173 utils.BootnodesFlag, 174 utils.BootnodesV4Flag, 175 utils.BootnodesV5Flag, 176 utils.ListenPortFlag, 177 utils.MaxPeersFlag, 178 utils.MaxPendingPeersFlag, 179 utils.NATFlag, 180 utils.NoDiscoverFlag, 181 utils.DiscoveryV5Flag, 182 utils.NetrestrictFlag, 183 utils.NodeKeyFileFlag, 184 utils.NodeKeyHexFlag, 185 }, 186 }, 187 { 188 Name: "MINER", 189 Flags: []cli.Flag{ 190 utils.MiningEnabledFlag, 191 utils.MinerThreadsFlag, 192 utils.MinerNotifyFlag, 193 utils.MinerGasPriceFlag, 194 utils.MinerGasTargetFlag, 195 utils.MinerGasLimitFlag, 196 utils.MinerEtherbaseFlag, 197 utils.MinerExtraDataFlag, 198 utils.MinerRecommitIntervalFlag, 199 utils.MinerNoVerfiyFlag, 200 }, 201 }, 202 { 203 Name: "GAS PRICE ORACLE", 204 Flags: []cli.Flag{ 205 utils.GpoBlocksFlag, 206 utils.GpoPercentileFlag, 207 }, 208 }, 209 { 210 Name: "VIRTUAL MACHINE", 211 Flags: []cli.Flag{ 212 utils.VMEnableDebugFlag, 213 utils.EVMInterpreterFlag, 214 utils.EWASMInterpreterFlag, 215 }, 216 }, 217 { 218 Name: "LOGGING AND DEBUGGING", 219 Flags: append([]cli.Flag{ 220 utils.FakePoWFlag, 221 utils.NoCompactionFlag, 222 }, debug.Flags...), 223 }, 224 { 225 Name: "METRICS AND STATS", 226 Flags: []cli.Flag{ 227 utils.MetricsEnabledFlag, 228 utils.MetricsEnableInfluxDBFlag, 229 utils.MetricsInfluxDBEndpointFlag, 230 utils.MetricsInfluxDBDatabaseFlag, 231 utils.MetricsInfluxDBUsernameFlag, 232 utils.MetricsInfluxDBPasswordFlag, 233 utils.MetricsInfluxDBHostTagFlag, 234 }, 235 }, 236 { 237 Name: "WHISPER (EXPERIMENTAL)", 238 Flags: whisperFlags, 239 }, 240 { 241 Name: "DEPRECATED", 242 Flags: []cli.Flag{ 243 utils.MinerLegacyThreadsFlag, 244 utils.MinerLegacyGasTargetFlag, 245 utils.MinerLegacyGasPriceFlag, 246 utils.MinerLegacyEtherbaseFlag, 247 utils.MinerLegacyExtraDataFlag, 248 }, 249 }, 250 { 251 Name: "MISC", 252 }, 253 } 254 255 // byCategory sorts an array of flagGroup by Name in the order 256 // defined in AppHelpFlagGroups. 257 type byCategory []flagGroup 258 259 func (a byCategory) Len() int { return len(a) } 260 func (a byCategory) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 261 func (a byCategory) Less(i, j int) bool { 262 iCat, jCat := a[i].Name, a[j].Name 263 iIdx, jIdx := len(AppHelpFlagGroups), len(AppHelpFlagGroups) // ensure non categorized flags come last 264 265 for i, group := range AppHelpFlagGroups { 266 if iCat == group.Name { 267 iIdx = i 268 } 269 if jCat == group.Name { 270 jIdx = i 271 } 272 } 273 274 return iIdx < jIdx 275 } 276 277 func flagCategory(flag cli.Flag) string { 278 for _, category := range AppHelpFlagGroups { 279 for _, flg := range category.Flags { 280 if flg.GetName() == flag.GetName() { 281 return category.Name 282 } 283 } 284 } 285 return "MISC" 286 } 287 288 func init() { 289 // Override the default app help template 290 cli.AppHelpTemplate = AppHelpTemplate 291 292 // Define a one shot struct to pass to the usage template 293 type helpData struct { 294 App interface{} 295 FlagGroups []flagGroup 296 } 297 298 // Override the default app help printer, but only for the global app help 299 originalHelpPrinter := cli.HelpPrinter 300 cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) { 301 if tmpl == AppHelpTemplate { 302 // Iterate over all the flags and add any uncategorized ones 303 categorized := make(map[string]struct{}) 304 for _, group := range AppHelpFlagGroups { 305 for _, flag := range group.Flags { 306 categorized[flag.String()] = struct{}{} 307 } 308 } 309 uncategorized := []cli.Flag{} 310 for _, flag := range data.(*cli.App).Flags { 311 if _, ok := categorized[flag.String()]; !ok { 312 if strings.HasPrefix(flag.GetName(), "dashboard") { 313 continue 314 } 315 uncategorized = append(uncategorized, flag) 316 } 317 } 318 if len(uncategorized) > 0 { 319 // Append all ungategorized options to the misc group 320 miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags) 321 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...) 322 323 // Make sure they are removed afterwards 324 defer func() { 325 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs] 326 }() 327 } 328 // Render out custom usage screen 329 originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups}) 330 } else if tmpl == utils.CommandHelpTemplate { 331 // Iterate over all command specific flags and categorize them 332 categorized := make(map[string][]cli.Flag) 333 for _, flag := range data.(cli.Command).Flags { 334 if _, ok := categorized[flag.String()]; !ok { 335 categorized[flagCategory(flag)] = append(categorized[flagCategory(flag)], flag) 336 } 337 } 338 339 // sort to get a stable ordering 340 sorted := make([]flagGroup, 0, len(categorized)) 341 for cat, flgs := range categorized { 342 sorted = append(sorted, flagGroup{cat, flgs}) 343 } 344 sort.Sort(byCategory(sorted)) 345 346 // add sorted array to data and render with default printer 347 originalHelpPrinter(w, tmpl, map[string]interface{}{ 348 "cmd": data, 349 "categorizedFlags": sorted, 350 }) 351 } else { 352 originalHelpPrinter(w, tmpl, data) 353 } 354 } 355 }