usage.go 5.6 KB

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