github.com/ethereum/go-ethereum@v1.10.9/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 "github.com/ethereum/go-ethereum/internal/flags" 28 "gopkg.in/urfave/cli.v1" 29 ) 30 31 // AppHelpFlagGroups is the application flags, grouped by functionality. 32 var AppHelpFlagGroups = []flags.FlagGroup{ 33 { 34 Name: "ETHEREUM", 35 Flags: []cli.Flag{ 36 configFileFlag, 37 utils.DataDirFlag, 38 utils.AncientFlag, 39 utils.MinFreeDiskSpaceFlag, 40 utils.KeyStoreDirFlag, 41 utils.USBFlag, 42 utils.SmartCardDaemonPathFlag, 43 utils.NetworkIdFlag, 44 utils.MainnetFlag, 45 utils.GoerliFlag, 46 utils.RinkebyFlag, 47 utils.RopstenFlag, 48 utils.SyncModeFlag, 49 utils.ExitWhenSyncedFlag, 50 utils.GCModeFlag, 51 utils.TxLookupLimitFlag, 52 utils.EthStatsURLFlag, 53 utils.IdentityFlag, 54 utils.LightKDFFlag, 55 utils.WhitelistFlag, 56 }, 57 }, 58 { 59 Name: "LIGHT CLIENT", 60 Flags: []cli.Flag{ 61 utils.LightServeFlag, 62 utils.LightIngressFlag, 63 utils.LightEgressFlag, 64 utils.LightMaxPeersFlag, 65 utils.UltraLightServersFlag, 66 utils.UltraLightFractionFlag, 67 utils.UltraLightOnlyAnnounceFlag, 68 utils.LightNoPruneFlag, 69 utils.LightNoSyncServeFlag, 70 }, 71 }, 72 { 73 Name: "DEVELOPER CHAIN", 74 Flags: []cli.Flag{ 75 utils.DeveloperFlag, 76 utils.DeveloperPeriodFlag, 77 }, 78 }, 79 { 80 Name: "ETHASH", 81 Flags: []cli.Flag{ 82 utils.EthashCacheDirFlag, 83 utils.EthashCachesInMemoryFlag, 84 utils.EthashCachesOnDiskFlag, 85 utils.EthashCachesLockMmapFlag, 86 utils.EthashDatasetDirFlag, 87 utils.EthashDatasetsInMemoryFlag, 88 utils.EthashDatasetsOnDiskFlag, 89 utils.EthashDatasetsLockMmapFlag, 90 }, 91 }, 92 { 93 Name: "TRANSACTION POOL", 94 Flags: []cli.Flag{ 95 utils.TxPoolLocalsFlag, 96 utils.TxPoolNoLocalsFlag, 97 utils.TxPoolJournalFlag, 98 utils.TxPoolRejournalFlag, 99 utils.TxPoolPriceLimitFlag, 100 utils.TxPoolPriceBumpFlag, 101 utils.TxPoolAccountSlotsFlag, 102 utils.TxPoolGlobalSlotsFlag, 103 utils.TxPoolAccountQueueFlag, 104 utils.TxPoolGlobalQueueFlag, 105 utils.TxPoolLifetimeFlag, 106 }, 107 }, 108 { 109 Name: "PERFORMANCE TUNING", 110 Flags: []cli.Flag{ 111 utils.CacheFlag, 112 utils.CacheDatabaseFlag, 113 utils.CacheTrieFlag, 114 utils.CacheTrieJournalFlag, 115 utils.CacheTrieRejournalFlag, 116 utils.CacheGCFlag, 117 utils.CacheSnapshotFlag, 118 utils.CacheNoPrefetchFlag, 119 utils.CachePreimagesFlag, 120 }, 121 }, 122 { 123 Name: "ACCOUNT", 124 Flags: []cli.Flag{ 125 utils.UnlockedAccountFlag, 126 utils.PasswordFileFlag, 127 utils.ExternalSignerFlag, 128 utils.InsecureUnlockAllowedFlag, 129 }, 130 }, 131 { 132 Name: "API AND CONSOLE", 133 Flags: []cli.Flag{ 134 utils.IPCDisabledFlag, 135 utils.IPCPathFlag, 136 utils.HTTPEnabledFlag, 137 utils.HTTPListenAddrFlag, 138 utils.HTTPPortFlag, 139 utils.HTTPApiFlag, 140 utils.HTTPPathPrefixFlag, 141 utils.HTTPCORSDomainFlag, 142 utils.HTTPVirtualHostsFlag, 143 utils.WSEnabledFlag, 144 utils.WSListenAddrFlag, 145 utils.WSPortFlag, 146 utils.WSApiFlag, 147 utils.WSPathPrefixFlag, 148 utils.WSAllowedOriginsFlag, 149 utils.GraphQLEnabledFlag, 150 utils.GraphQLCORSDomainFlag, 151 utils.GraphQLVirtualHostsFlag, 152 utils.RPCGlobalGasCapFlag, 153 utils.RPCGlobalTxFeeCapFlag, 154 utils.AllowUnprotectedTxs, 155 utils.JSpathFlag, 156 utils.ExecFlag, 157 utils.PreloadJSFlag, 158 }, 159 }, 160 { 161 Name: "NETWORKING", 162 Flags: []cli.Flag{ 163 utils.BootnodesFlag, 164 utils.DNSDiscoveryFlag, 165 utils.ListenPortFlag, 166 utils.MaxPeersFlag, 167 utils.MaxPendingPeersFlag, 168 utils.NATFlag, 169 utils.NoDiscoverFlag, 170 utils.DiscoveryV5Flag, 171 utils.NetrestrictFlag, 172 utils.NodeKeyFileFlag, 173 utils.NodeKeyHexFlag, 174 }, 175 }, 176 { 177 Name: "MINER", 178 Flags: []cli.Flag{ 179 utils.MiningEnabledFlag, 180 utils.MinerThreadsFlag, 181 utils.MinerNotifyFlag, 182 utils.MinerNotifyFullFlag, 183 utils.MinerGasPriceFlag, 184 utils.MinerGasLimitFlag, 185 utils.MinerEtherbaseFlag, 186 utils.MinerExtraDataFlag, 187 utils.MinerRecommitIntervalFlag, 188 utils.MinerNoVerifyFlag, 189 }, 190 }, 191 { 192 Name: "GAS PRICE ORACLE", 193 Flags: []cli.Flag{ 194 utils.GpoBlocksFlag, 195 utils.GpoPercentileFlag, 196 utils.GpoMaxGasPriceFlag, 197 utils.GpoIgnoreGasPriceFlag, 198 }, 199 }, 200 { 201 Name: "VIRTUAL MACHINE", 202 Flags: []cli.Flag{ 203 utils.VMEnableDebugFlag, 204 }, 205 }, 206 { 207 Name: "LOGGING AND DEBUGGING", 208 Flags: append([]cli.Flag{ 209 utils.FakePoWFlag, 210 utils.NoCompactionFlag, 211 }, debug.Flags...), 212 }, 213 { 214 Name: "METRICS AND STATS", 215 Flags: metricsFlags, 216 }, 217 { 218 Name: "ALIASED (deprecated)", 219 Flags: []cli.Flag{ 220 utils.NoUSBFlag, 221 }, 222 }, 223 { 224 Name: "MISC", 225 Flags: []cli.Flag{ 226 utils.SnapshotFlag, 227 utils.BloomFilterSizeFlag, 228 cli.HelpFlag, 229 utils.CatalystFlag, 230 }, 231 }, 232 } 233 234 func init() { 235 // Override the default app help template 236 cli.AppHelpTemplate = flags.AppHelpTemplate 237 238 // Override the default app help printer, but only for the global app help 239 originalHelpPrinter := cli.HelpPrinter 240 cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) { 241 if tmpl == flags.AppHelpTemplate { 242 // Iterate over all the flags and add any uncategorized ones 243 categorized := make(map[string]struct{}) 244 for _, group := range AppHelpFlagGroups { 245 for _, flag := range group.Flags { 246 categorized[flag.String()] = struct{}{} 247 } 248 } 249 deprecated := make(map[string]struct{}) 250 for _, flag := range utils.DeprecatedFlags { 251 deprecated[flag.String()] = struct{}{} 252 } 253 // Only add uncategorized flags if they are not deprecated 254 var uncategorized []cli.Flag 255 for _, flag := range data.(*cli.App).Flags { 256 if _, ok := categorized[flag.String()]; !ok { 257 if _, ok := deprecated[flag.String()]; !ok { 258 uncategorized = append(uncategorized, flag) 259 } 260 } 261 } 262 if len(uncategorized) > 0 { 263 // Append all ungategorized options to the misc group 264 miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags) 265 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...) 266 267 // Make sure they are removed afterwards 268 defer func() { 269 AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs] 270 }() 271 } 272 // Render out custom usage screen 273 originalHelpPrinter(w, tmpl, flags.HelpData{App: data, FlagGroups: AppHelpFlagGroups}) 274 } else if tmpl == flags.CommandHelpTemplate { 275 // Iterate over all command specific flags and categorize them 276 categorized := make(map[string][]cli.Flag) 277 for _, flag := range data.(cli.Command).Flags { 278 if _, ok := categorized[flag.String()]; !ok { 279 categorized[flags.FlagCategory(flag, AppHelpFlagGroups)] = append(categorized[flags.FlagCategory(flag, AppHelpFlagGroups)], flag) 280 } 281 } 282 283 // sort to get a stable ordering 284 sorted := make([]flags.FlagGroup, 0, len(categorized)) 285 for cat, flgs := range categorized { 286 sorted = append(sorted, flags.FlagGroup{Name: cat, Flags: flgs}) 287 } 288 sort.Sort(flags.ByCategory(sorted)) 289 290 // add sorted array to data and render with default printer 291 originalHelpPrinter(w, tmpl, map[string]interface{}{ 292 "cmd": data, 293 "categorizedFlags": sorted, 294 }) 295 } else { 296 originalHelpPrinter(w, tmpl, data) 297 } 298 } 299 }