usage.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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.IPCPathFlag,
  110. utils.RPCCORSDomainFlag,
  111. utils.JSpathFlag,
  112. utils.ExecFlag,
  113. utils.PreloadJSFlag,
  114. },
  115. },
  116. {
  117. Name: "NETWORKING",
  118. Flags: []cli.Flag{
  119. utils.BootnodesFlag,
  120. utils.ListenPortFlag,
  121. utils.MaxPeersFlag,
  122. utils.MaxPendingPeersFlag,
  123. utils.NATFlag,
  124. utils.NoDiscoverFlag,
  125. utils.DiscoveryV5Flag,
  126. utils.NodeKeyFileFlag,
  127. utils.NodeKeyHexFlag,
  128. },
  129. },
  130. {
  131. Name: "MINER",
  132. Flags: []cli.Flag{
  133. utils.MiningEnabledFlag,
  134. utils.MinerThreadsFlag,
  135. utils.EtherbaseFlag,
  136. utils.TargetGasLimitFlag,
  137. utils.GasPriceFlag,
  138. utils.ExtraDataFlag,
  139. },
  140. },
  141. {
  142. Name: "GAS PRICE ORACLE",
  143. Flags: []cli.Flag{
  144. utils.GpoBlocksFlag,
  145. utils.GpoPercentileFlag,
  146. },
  147. },
  148. {
  149. Name: "VIRTUAL MACHINE",
  150. Flags: []cli.Flag{
  151. utils.VMEnableDebugFlag,
  152. },
  153. },
  154. {
  155. Name: "LOGGING AND DEBUGGING",
  156. Flags: append([]cli.Flag{
  157. utils.EthStatsURLFlag,
  158. utils.MetricsEnabledFlag,
  159. utils.FakePoWFlag,
  160. }, debug.Flags...),
  161. },
  162. {
  163. Name: "EXPERIMENTAL",
  164. Flags: []cli.Flag{
  165. utils.WhisperEnabledFlag,
  166. },
  167. },
  168. {
  169. Name: "MISCELLANEOUS",
  170. Flags: []cli.Flag{
  171. utils.SolcPathFlag,
  172. },
  173. },
  174. }
  175. func init() {
  176. // Override the default app help template
  177. cli.AppHelpTemplate = AppHelpTemplate
  178. // Define a one shot struct to pass to the usage template
  179. type helpData struct {
  180. App interface{}
  181. FlagGroups []flagGroup
  182. }
  183. // Override the default app help printer, but only for the global app help
  184. originalHelpPrinter := cli.HelpPrinter
  185. cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
  186. if tmpl == AppHelpTemplate {
  187. // Iterate over all the flags and add any uncategorized ones
  188. categorized := make(map[string]struct{})
  189. for _, group := range AppHelpFlagGroups {
  190. for _, flag := range group.Flags {
  191. categorized[flag.String()] = struct{}{}
  192. }
  193. }
  194. uncategorized := []cli.Flag{}
  195. for _, flag := range data.(*cli.App).Flags {
  196. if _, ok := categorized[flag.String()]; !ok {
  197. uncategorized = append(uncategorized, flag)
  198. }
  199. }
  200. if len(uncategorized) > 0 {
  201. // Append all ungategorized options to the misc group
  202. miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
  203. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
  204. // Make sure they are removed afterwards
  205. defer func() {
  206. AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
  207. }()
  208. }
  209. // Render out custom usage screen
  210. originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups})
  211. } else {
  212. originalHelpPrinter(w, tmpl, data)
  213. }
  214. }
  215. }