usage.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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.OlympicFlag,
  62. utils.TestNetFlag,
  63. utils.DevModeFlag,
  64. utils.IdentityFlag,
  65. utils.FastSyncFlag,
  66. utils.LightModeFlag,
  67. utils.LightServFlag,
  68. utils.LightPeersFlag,
  69. utils.LightKDFFlag,
  70. },
  71. },
  72. {
  73. Name: "PERFORMANCE TUNING",
  74. Flags: []cli.Flag{
  75. utils.CacheFlag,
  76. utils.TrieCacheGenFlag,
  77. },
  78. },
  79. {
  80. Name: "ACCOUNT",
  81. Flags: []cli.Flag{
  82. utils.UnlockedAccountFlag,
  83. utils.PasswordFileFlag,
  84. },
  85. },
  86. {
  87. Name: "API AND CONSOLE",
  88. Flags: []cli.Flag{
  89. utils.RPCEnabledFlag,
  90. utils.RPCListenAddrFlag,
  91. utils.RPCPortFlag,
  92. utils.RPCApiFlag,
  93. utils.WSEnabledFlag,
  94. utils.WSListenAddrFlag,
  95. utils.WSPortFlag,
  96. utils.WSApiFlag,
  97. utils.WSAllowedOriginsFlag,
  98. utils.IPCDisabledFlag,
  99. utils.IPCApiFlag,
  100. utils.IPCPathFlag,
  101. utils.RPCCORSDomainFlag,
  102. utils.JSpathFlag,
  103. utils.ExecFlag,
  104. utils.PreloadJSFlag,
  105. },
  106. },
  107. {
  108. Name: "NETWORKING",
  109. Flags: []cli.Flag{
  110. utils.BootnodesFlag,
  111. utils.ListenPortFlag,
  112. utils.MaxPeersFlag,
  113. utils.MaxPendingPeersFlag,
  114. utils.NATFlag,
  115. utils.NoDiscoverFlag,
  116. utils.DiscoveryV5Flag,
  117. utils.NodeKeyFileFlag,
  118. utils.NodeKeyHexFlag,
  119. },
  120. },
  121. {
  122. Name: "MINER",
  123. Flags: []cli.Flag{
  124. utils.MiningEnabledFlag,
  125. utils.MinerThreadsFlag,
  126. utils.AutoDAGFlag,
  127. utils.EtherbaseFlag,
  128. utils.TargetGasLimitFlag,
  129. utils.GasPriceFlag,
  130. utils.ExtraDataFlag,
  131. },
  132. },
  133. {
  134. Name: "GAS PRICE ORACLE",
  135. Flags: []cli.Flag{
  136. utils.GpoMinGasPriceFlag,
  137. utils.GpoMaxGasPriceFlag,
  138. utils.GpoFullBlockRatioFlag,
  139. utils.GpobaseStepDownFlag,
  140. utils.GpobaseStepUpFlag,
  141. utils.GpobaseCorrectionFactorFlag,
  142. },
  143. },
  144. {
  145. Name: "VIRTUAL MACHINE",
  146. Flags: []cli.Flag{
  147. utils.VMEnableJitFlag,
  148. utils.VMForceJitFlag,
  149. utils.VMJitCacheFlag,
  150. },
  151. },
  152. {
  153. Name: "LOGGING AND DEBUGGING",
  154. Flags: append([]cli.Flag{
  155. utils.EthStatsURLFlag,
  156. utils.MetricsEnabledFlag,
  157. utils.FakePoWFlag,
  158. }, debug.Flags...),
  159. },
  160. {
  161. Name: "EXPERIMENTAL",
  162. Flags: []cli.Flag{
  163. utils.WhisperEnabledFlag,
  164. utils.NatspecEnabledFlag,
  165. },
  166. },
  167. {
  168. Name: "MISCELLANEOUS",
  169. Flags: []cli.Flag{
  170. utils.SolcPathFlag,
  171. },
  172. },
  173. }
  174. func init() {
  175. // Override the default app help template
  176. cli.AppHelpTemplate = AppHelpTemplate
  177. // Define a one shot struct to pass to the usage template
  178. type helpData struct {
  179. App interface{}
  180. FlagGroups []flagGroup
  181. }
  182. // Override the default app help printer, but only for the global app help
  183. originalHelpPrinter := cli.HelpPrinter
  184. cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
  185. if tmpl == AppHelpTemplate {
  186. // Iterate over all the flags and add any uncategorized ones
  187. categorized := make(map[string]struct{})
  188. for _, group := range AppHelpFlagGroups {
  189. for _, flag := range group.Flags {
  190. categorized[flag.String()] = struct{}{}
  191. }
  192. }
  193. uncategorized := []cli.Flag{}
  194. for _, flag := range data.(*cli.App).Flags {
  195. if _, ok := categorized[flag.String()]; !ok {
  196. uncategorized = append(uncategorized, flag)
  197. }
  198. }
  199. if len(uncategorized) > 0 {
  200. // Append all ungategorized options to the misc group
  201. miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
  202. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
  203. // Make sure they are removed afterwards
  204. defer func() {
  205. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
  206. }()
  207. }
  208. // Render out custom usage screen
  209. originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups})
  210. } else {
  211. originalHelpPrinter(w, tmpl, data)
  212. }
  213. }
  214. }