usage.go 8.0 KB

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