github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/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  	"gopkg.in/urfave/cli.v1"
    25  )
    26  
    27  // AppHelpTemplate is the test template for the default, global app help topic.
    28  var AppHelpTemplate = `NAME:
    29     {{.App.Name}} - {{.App.Usage}}
    30  
    31  USAGE:
    32     {{.App.HelpName}} [options]{{if .App.Commands}} <command> [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}}
    33  
    34  VERSION:
    35     {{.App.Version}}{{if .CommandAndFlagGroups}}
    36  
    37  COMMANDS AND FLAGS:
    38  
    39  {{range .CommandAndFlagGroups}}{{.Name}}
    40  ------------------------------------------------------------------------
    41    {{if .Commands}}{{range .Commands}}
    42      {{join .Names ", "}}{{ "\t" }}{{.Usage}}{{ if .Subcommands }}{{ "\n\n" }}{{end}}{{range .Subcommands}}{{"\t"}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}{{"\n"}}{{end}}{{end}}
    43    
    44    {{end}}{{range .Flags}}{{.}}
    45    {{end}}
    46  {{end}}{{end}}{{if .App.Copyright }}
    47  
    48  COPYRIGHT:
    49     {{.App.Copyright}}
    50     {{end}}
    51  `
    52  
    53  // flagGroup is a collection of commands and/or flags belonging to a single topic.
    54  type flagGroup struct {
    55  	Name     string
    56  	Flags    []cli.Flag
    57  	Commands []cli.Command
    58  }
    59  
    60  // AppHelpFlagAndCommandGroups is the application flags, grouped by functionality.
    61  var AppHelpFlagAndCommandGroups = []flagGroup{
    62  	{
    63  		Name: "ETHEREUM",
    64  		Commands: []cli.Command{
    65  			importCommand,
    66  			exportCommand,
    67  			dumpChainConfigCommand,
    68  			dumpCommand,
    69  			rollbackCommand,
    70  			recoverCommand,
    71  			resetCommand,
    72  		},
    73  		Flags: []cli.Flag{
    74  			DataDirFlag,
    75  			ChainIdentityFlag,
    76  			NetworkIdFlag,
    77  			DevModeFlag,
    78  			NodeNameFlag,
    79  			FastSyncFlag,
    80  			CacheFlag,
    81  			LightKDFFlag,
    82  			SputnikVMFlag,
    83  			BlockchainVersionFlag,
    84  		},
    85  	},
    86  	{
    87  		Name: "ACCOUNT",
    88  		Commands: []cli.Command{
    89  			accountCommand,
    90  			walletCommand,
    91  			buildAddrTxIndexCommand,
    92  		},
    93  		Flags: []cli.Flag{
    94  			KeyStoreDirFlag,
    95  			UnlockedAccountFlag,
    96  			PasswordFileFlag,
    97  			AccountsIndexFlag,
    98  			AddrTxIndexFlag,
    99  			AddrTxIndexAutoBuildFlag,
   100  		},
   101  	},
   102  	{
   103  		Name: "API AND CONSOLE",
   104  		Commands: []cli.Command{
   105  			consoleCommand,
   106  			attachCommand,
   107  			javascriptCommand,
   108  			apiCommand,
   109  		},
   110  		Flags: []cli.Flag{
   111  			RPCEnabledFlag,
   112  			RPCListenAddrFlag,
   113  			RPCPortFlag,
   114  			RPCApiFlag,
   115  			WSEnabledFlag,
   116  			WSListenAddrFlag,
   117  			WSPortFlag,
   118  			WSApiFlag,
   119  			WSAllowedOriginsFlag,
   120  			IPCDisabledFlag,
   121  			IPCApiFlag,
   122  			IPCPathFlag,
   123  			RPCCORSDomainFlag,
   124  			JSpathFlag,
   125  			ExecFlag,
   126  			PreloadJSFlag,
   127  		},
   128  	},
   129  	{
   130  		Name: "NETWORKING",
   131  		Flags: []cli.Flag{
   132  			BootnodesFlag,
   133  			ListenPortFlag,
   134  			MaxPeersFlag,
   135  			MaxPendingPeersFlag,
   136  			NATFlag,
   137  			NoDiscoverFlag,
   138  			NodeKeyFileFlag,
   139  			NodeKeyHexFlag,
   140  		},
   141  	},
   142  	{
   143  		Name: "MINER",
   144  		Commands: []cli.Command{
   145  			makeDagCommand,
   146  		},
   147  		Flags: []cli.Flag{
   148  			MiningEnabledFlag,
   149  			MinerThreadsFlag,
   150  			MiningGPUFlag,
   151  			AutoDAGFlag,
   152  			EtherbaseFlag,
   153  			TargetGasLimitFlag,
   154  			GasPriceFlag,
   155  			ExtraDataFlag,
   156  		},
   157  	},
   158  	{
   159  		Name: "GAS PRICE ORACLE",
   160  		Flags: []cli.Flag{
   161  			GpoMinGasPriceFlag,
   162  			GpoMaxGasPriceFlag,
   163  			GpoFullBlockRatioFlag,
   164  			GpobaseStepDownFlag,
   165  			GpobaseStepUpFlag,
   166  			GpobaseCorrectionFactorFlag,
   167  		},
   168  	},
   169  	{
   170  		Name: "LOGGING AND DEBUGGING",
   171  		Commands: []cli.Command{
   172  			versionCommand,
   173  			statusCommand,
   174  			monitorCommand,
   175  			makeMlogDocCommand,
   176  			gpuInfoCommand,
   177  			gpuBenchCommand,
   178  		},
   179  		Flags: []cli.Flag{
   180  			VerbosityFlag,
   181  			VModuleFlag,
   182  			LogDirFlag,
   183  			LogMaxSizeFlag,
   184  			LogMinSizeFlag,
   185  			LogMaxTotalSizeFlag,
   186  			LogIntervalFlag,
   187  			LogMaxAgeFlag,
   188  			LogCompressFlag,
   189  			LogStatusFlag,
   190  			DisplayFlag,
   191  			DisplayFormatFlag,
   192  			NeckbeardFlag,
   193  			MLogFlag,
   194  			MLogDirFlag,
   195  			MLogComponentsFlag,
   196  			BacktraceAtFlag,
   197  			MetricsFlag,
   198  			FakePoWFlag,
   199  		},
   200  	},
   201  	{
   202  		Name: "EXPERIMENTAL",
   203  		Flags: []cli.Flag{
   204  			WhisperEnabledFlag,
   205  			NatspecEnabledFlag,
   206  			DisplayFlag,
   207  			DisplayFormatFlag,
   208  			NeckbeardFlag,
   209  		},
   210  	},
   211  	{
   212  		Name: "LEGACY",
   213  		Commands: []cli.Command{
   214  			upgradedbCommand,
   215  		},
   216  		Flags: []cli.Flag{
   217  			TestNetFlag,
   218  			Unused1,
   219  		},
   220  	},
   221  	{
   222  		Name: "MISCELLANEOUS",
   223  		Flags: []cli.Flag{
   224  			SolcPathFlag,
   225  		},
   226  	},
   227  }
   228  
   229  func init() {
   230  	// Override the default app help template
   231  	cli.AppHelpTemplate = AppHelpTemplate
   232  
   233  	// Define a one shot struct to pass to the usage template
   234  	type helpData struct {
   235  		App                  interface{}
   236  		CommandAndFlagGroups []flagGroup
   237  	}
   238  	// Override the default app help printer, but only for the global app help
   239  	originalHelpPrinter := cli.HelpPrinter
   240  	cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
   241  		if tmpl == AppHelpTemplate {
   242  			// Iterate over all the flags and add any uncategorized ones
   243  			categorized := make(map[string]struct{})
   244  			for _, group := range AppHelpFlagAndCommandGroups {
   245  				for _, flag := range group.Flags {
   246  					categorized[flag.String()] = struct{}{}
   247  				}
   248  			}
   249  			uncategorized := []cli.Flag{}
   250  			for _, flag := range data.(*cli.App).Flags {
   251  				if _, ok := categorized[flag.String()]; !ok {
   252  					uncategorized = append(uncategorized, flag)
   253  				}
   254  			}
   255  			if len(uncategorized) > 0 {
   256  				// Append all ungategorized options to the misc group
   257  				miscs := len(AppHelpFlagAndCommandGroups[len(AppHelpFlagAndCommandGroups)-1].Flags)
   258  				AppHelpFlagAndCommandGroups[len(AppHelpFlagAndCommandGroups)-1].Flags = append(AppHelpFlagAndCommandGroups[len(AppHelpFlagAndCommandGroups)-1].Flags, uncategorized...)
   259  
   260  				// Make sure they are removed afterwards
   261  				defer func() {
   262  					AppHelpFlagAndCommandGroups[len(AppHelpFlagAndCommandGroups)-1].Flags = AppHelpFlagAndCommandGroups[len(AppHelpFlagAndCommandGroups)-1].Flags[:miscs]
   263  				}()
   264  			}
   265  			// Render out custom usage screen
   266  			originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagAndCommandGroups})
   267  		} else {
   268  			originalHelpPrinter(w, tmpl, data)
   269  		}
   270  	}
   271  }