usage.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. // Contains the geth command usage template and generator.
  17. package main
  18. import (
  19. "io"
  20. "sort"
  21. "github.com/ethereum/go-ethereum/cmd/utils"
  22. "github.com/ethereum/go-ethereum/internal/debug"
  23. "github.com/ethereum/go-ethereum/internal/flags"
  24. "gopkg.in/urfave/cli.v1"
  25. )
  26. // AppHelpFlagGroups is the application flags, grouped by functionality.
  27. var AppHelpFlagGroups = []flags.FlagGroup{
  28. {
  29. Name: "ETHEREUM",
  30. Flags: []cli.Flag{
  31. configFileFlag,
  32. utils.DataDirFlag,
  33. utils.AncientFlag,
  34. utils.MinFreeDiskSpaceFlag,
  35. utils.KeyStoreDirFlag,
  36. utils.NoUSBFlag,
  37. utils.DirectBroadcastFlag,
  38. utils.DisableSnapProtocolFlag,
  39. utils.RangeLimitFlag,
  40. utils.SmartCardDaemonPathFlag,
  41. utils.NetworkIdFlag,
  42. utils.MainnetFlag,
  43. utils.GoerliFlag,
  44. utils.RinkebyFlag,
  45. utils.YoloV3Flag,
  46. utils.RopstenFlag,
  47. utils.SyncModeFlag,
  48. utils.ExitWhenSyncedFlag,
  49. utils.GCModeFlag,
  50. utils.TxLookupLimitFlag,
  51. utils.EthStatsURLFlag,
  52. utils.IdentityFlag,
  53. utils.LightKDFFlag,
  54. utils.WhitelistFlag,
  55. utils.TriesInMemoryFlag,
  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. utils.TxPoolReannounceTimeFlag,
  107. },
  108. },
  109. {
  110. Name: "PERFORMANCE TUNING",
  111. Flags: []cli.Flag{
  112. utils.CacheFlag,
  113. utils.CacheDatabaseFlag,
  114. utils.CacheTrieFlag,
  115. utils.CacheTrieJournalFlag,
  116. utils.CacheTrieRejournalFlag,
  117. utils.CacheGCFlag,
  118. utils.CacheSnapshotFlag,
  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.MinerGasTargetFlag,
  185. utils.MinerGasLimitFlag,
  186. utils.MinerEtherbaseFlag,
  187. utils.MinerExtraDataFlag,
  188. utils.MinerRecommitIntervalFlag,
  189. utils.MinerDelayLeftoverFlag,
  190. utils.MinerNoVerfiyFlag,
  191. },
  192. },
  193. {
  194. Name: "GAS PRICE ORACLE",
  195. Flags: []cli.Flag{
  196. utils.GpoBlocksFlag,
  197. utils.GpoPercentileFlag,
  198. utils.GpoMaxGasPriceFlag,
  199. },
  200. },
  201. {
  202. Name: "VIRTUAL MACHINE",
  203. Flags: []cli.Flag{
  204. utils.VMEnableDebugFlag,
  205. utils.EVMInterpreterFlag,
  206. utils.EWASMInterpreterFlag,
  207. },
  208. },
  209. {
  210. Name: "LOGGING AND DEBUGGING",
  211. Flags: append([]cli.Flag{
  212. utils.FakePoWFlag,
  213. utils.NoCompactionFlag,
  214. }, debug.Flags...),
  215. },
  216. {
  217. Name: "METRICS AND STATS",
  218. Flags: metricsFlags,
  219. },
  220. {
  221. Name: "ALIASED (deprecated)",
  222. Flags: []cli.Flag{
  223. utils.NoUSBFlag,
  224. utils.LegacyRPCEnabledFlag,
  225. utils.LegacyRPCListenAddrFlag,
  226. utils.LegacyRPCPortFlag,
  227. utils.LegacyRPCCORSDomainFlag,
  228. utils.LegacyRPCVirtualHostsFlag,
  229. utils.LegacyRPCApiFlag,
  230. },
  231. },
  232. {
  233. Name: "MISC",
  234. Flags: []cli.Flag{
  235. utils.SnapshotFlag,
  236. utils.BloomFilterSizeFlag,
  237. cli.HelpFlag,
  238. utils.CatalystFlag,
  239. },
  240. },
  241. }
  242. func init() {
  243. // Override the default app help template
  244. cli.AppHelpTemplate = flags.AppHelpTemplate
  245. // Override the default app help printer, but only for the global app help
  246. originalHelpPrinter := cli.HelpPrinter
  247. cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
  248. if tmpl == flags.AppHelpTemplate {
  249. // Iterate over all the flags and add any uncategorized ones
  250. categorized := make(map[string]struct{})
  251. for _, group := range AppHelpFlagGroups {
  252. for _, flag := range group.Flags {
  253. categorized[flag.String()] = struct{}{}
  254. }
  255. }
  256. deprecated := make(map[string]struct{})
  257. for _, flag := range utils.DeprecatedFlags {
  258. deprecated[flag.String()] = struct{}{}
  259. }
  260. // Only add uncategorized flags if they are not deprecated
  261. var uncategorized []cli.Flag
  262. for _, flag := range data.(*cli.App).Flags {
  263. if _, ok := categorized[flag.String()]; !ok {
  264. if _, ok := deprecated[flag.String()]; !ok {
  265. uncategorized = append(uncategorized, flag)
  266. }
  267. }
  268. }
  269. if len(uncategorized) > 0 {
  270. // Append all ungategorized options to the misc group
  271. miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
  272. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
  273. // Make sure they are removed afterwards
  274. defer func() {
  275. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
  276. }()
  277. }
  278. // Render out custom usage screen
  279. originalHelpPrinter(w, tmpl, flags.HelpData{App: data, FlagGroups: AppHelpFlagGroups})
  280. } else if tmpl == flags.CommandHelpTemplate {
  281. // Iterate over all command specific flags and categorize them
  282. categorized := make(map[string][]cli.Flag)
  283. for _, flag := range data.(cli.Command).Flags {
  284. if _, ok := categorized[flag.String()]; !ok {
  285. categorized[flags.FlagCategory(flag, AppHelpFlagGroups)] = append(categorized[flags.FlagCategory(flag, AppHelpFlagGroups)], flag)
  286. }
  287. }
  288. // sort to get a stable ordering
  289. sorted := make([]flags.FlagGroup, 0, len(categorized))
  290. for cat, flgs := range categorized {
  291. sorted = append(sorted, flags.FlagGroup{Name: cat, Flags: flgs})
  292. }
  293. sort.Sort(flags.ByCategory(sorted))
  294. // add sorted array to data and render with default printer
  295. originalHelpPrinter(w, tmpl, map[string]interface{}{
  296. "cmd": data,
  297. "categorizedFlags": sorted,
  298. })
  299. } else {
  300. originalHelpPrinter(w, tmpl, data)
  301. }
  302. }
  303. }