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