usage.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. "github.com/ethereum/go-ethereum/cmd/utils"
  21. "github.com/ethereum/go-ethereum/internal/debug"
  22. "gopkg.in/urfave/cli.v1"
  23. )
  24. // AppHelpTemplate is the test template for the default, global app help topic.
  25. var AppHelpTemplate = `NAME:
  26. {{.App.Name}} - {{.App.Usage}}
  27. Copyright 2013-2016 The go-ethereum Authors
  28. USAGE:
  29. {{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}}
  30. {{if .App.Version}}
  31. VERSION:
  32. {{.App.Version}}
  33. {{end}}{{if len .App.Authors}}
  34. AUTHOR(S):
  35. {{range .App.Authors}}{{ . }}{{end}}
  36. {{end}}{{if .App.Commands}}
  37. COMMANDS:
  38. {{range .App.Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
  39. {{end}}{{end}}{{if .FlagGroups}}
  40. {{range .FlagGroups}}{{.Name}} OPTIONS:
  41. {{range .Flags}}{{.}}
  42. {{end}}
  43. {{end}}{{end}}{{if .App.Copyright }}
  44. COPYRIGHT:
  45. {{.App.Copyright}}
  46. {{end}}
  47. `
  48. // flagGroup is a collection of flags belonging to a single topic.
  49. type flagGroup struct {
  50. Name string
  51. Flags []cli.Flag
  52. }
  53. // AppHelpFlagGroups is the application flags, grouped by functionality.
  54. var AppHelpFlagGroups = []flagGroup{
  55. {
  56. Name: "ETHEREUM",
  57. Flags: []cli.Flag{
  58. utils.DataDirFlag,
  59. utils.KeyStoreDirFlag,
  60. utils.NetworkIdFlag,
  61. utils.TestNetFlag,
  62. utils.DevModeFlag,
  63. utils.IdentityFlag,
  64. utils.FastSyncFlag,
  65. utils.LightModeFlag,
  66. utils.LightServFlag,
  67. utils.LightPeersFlag,
  68. utils.LightKDFFlag,
  69. },
  70. },
  71. {
  72. Name: "ETHASH",
  73. Flags: []cli.Flag{
  74. utils.EthashCacheDirFlag,
  75. utils.EthashCachesInMemoryFlag,
  76. utils.EthashCachesOnDiskFlag,
  77. utils.EthashDatasetDirFlag,
  78. utils.EthashDatasetsInMemoryFlag,
  79. utils.EthashDatasetsOnDiskFlag,
  80. },
  81. },
  82. {
  83. Name: "PERFORMANCE TUNING",
  84. Flags: []cli.Flag{
  85. utils.CacheFlag,
  86. utils.TrieCacheGenFlag,
  87. },
  88. },
  89. {
  90. Name: "ACCOUNT",
  91. Flags: []cli.Flag{
  92. utils.UnlockedAccountFlag,
  93. utils.PasswordFileFlag,
  94. },
  95. },
  96. {
  97. Name: "API AND CONSOLE",
  98. Flags: []cli.Flag{
  99. utils.RPCEnabledFlag,
  100. utils.RPCListenAddrFlag,
  101. utils.RPCPortFlag,
  102. utils.RPCApiFlag,
  103. utils.WSEnabledFlag,
  104. utils.WSListenAddrFlag,
  105. utils.WSPortFlag,
  106. utils.WSApiFlag,
  107. utils.WSAllowedOriginsFlag,
  108. utils.IPCDisabledFlag,
  109. utils.IPCApiFlag,
  110. utils.IPCPathFlag,
  111. utils.RPCCORSDomainFlag,
  112. utils.JSpathFlag,
  113. utils.ExecFlag,
  114. utils.PreloadJSFlag,
  115. },
  116. },
  117. {
  118. Name: "NETWORKING",
  119. Flags: []cli.Flag{
  120. utils.BootnodesFlag,
  121. utils.ListenPortFlag,
  122. utils.MaxPeersFlag,
  123. utils.MaxPendingPeersFlag,
  124. utils.NATFlag,
  125. utils.NoDiscoverFlag,
  126. utils.DiscoveryV5Flag,
  127. utils.NodeKeyFileFlag,
  128. utils.NodeKeyHexFlag,
  129. },
  130. },
  131. {
  132. Name: "MINER",
  133. Flags: []cli.Flag{
  134. utils.MiningEnabledFlag,
  135. utils.MinerThreadsFlag,
  136. utils.EtherbaseFlag,
  137. utils.TargetGasLimitFlag,
  138. utils.GasPriceFlag,
  139. utils.ExtraDataFlag,
  140. },
  141. },
  142. {
  143. Name: "GAS PRICE ORACLE",
  144. Flags: []cli.Flag{
  145. utils.GpoMinGasPriceFlag,
  146. utils.GpoMaxGasPriceFlag,
  147. utils.GpoFullBlockRatioFlag,
  148. utils.GpobaseStepDownFlag,
  149. utils.GpobaseStepUpFlag,
  150. utils.GpobaseCorrectionFactorFlag,
  151. },
  152. },
  153. {
  154. Name: "VIRTUAL MACHINE",
  155. Flags: []cli.Flag{
  156. utils.VMEnableJitFlag,
  157. utils.VMForceJitFlag,
  158. utils.VMJitCacheFlag,
  159. utils.VMEnableDebugFlag,
  160. },
  161. },
  162. {
  163. Name: "LOGGING AND DEBUGGING",
  164. Flags: append([]cli.Flag{
  165. utils.EthStatsURLFlag,
  166. utils.MetricsEnabledFlag,
  167. utils.FakePoWFlag,
  168. }, debug.Flags...),
  169. },
  170. {
  171. Name: "EXPERIMENTAL",
  172. Flags: []cli.Flag{
  173. utils.WhisperEnabledFlag,
  174. },
  175. },
  176. {
  177. Name: "MISCELLANEOUS",
  178. Flags: []cli.Flag{
  179. utils.SolcPathFlag,
  180. },
  181. },
  182. }
  183. func init() {
  184. // Override the default app help template
  185. cli.AppHelpTemplate = AppHelpTemplate
  186. // Define a one shot struct to pass to the usage template
  187. type helpData struct {
  188. App interface{}
  189. FlagGroups []flagGroup
  190. }
  191. // Override the default app help printer, but only for the global app help
  192. originalHelpPrinter := cli.HelpPrinter
  193. cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
  194. if tmpl == AppHelpTemplate {
  195. // Iterate over all the flags and add any uncategorized ones
  196. categorized := make(map[string]struct{})
  197. for _, group := range AppHelpFlagGroups {
  198. for _, flag := range group.Flags {
  199. categorized[flag.String()] = struct{}{}
  200. }
  201. }
  202. uncategorized := []cli.Flag{}
  203. for _, flag := range data.(*cli.App).Flags {
  204. if _, ok := categorized[flag.String()]; !ok {
  205. uncategorized = append(uncategorized, flag)
  206. }
  207. }
  208. if len(uncategorized) > 0 {
  209. // Append all ungategorized options to the misc group
  210. miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
  211. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
  212. // Make sure they are removed afterwards
  213. defer func() {
  214. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
  215. }()
  216. }
  217. // Render out custom usage screen
  218. originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups})
  219. } else {
  220. originalHelpPrinter(w, tmpl, data)
  221. }
  222. }
  223. }