github.com/avence12/go-ethereum@v1.5.10-0.20170320123548-1dfd65f6d047/cmd/geth/usage.go (about)

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