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