usage.go 5.4 KB

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