usage.go 5.5 KB

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